Check status of web pages without asking google

webchk.py

01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/usr/bin/env python
import socket
import sys
import argparse
parser = argparse.ArgumentParser()
parser.add_argument("-f", "--file", help="file name holding the list of webpages to test")
parser.add_argument("-o", "--host", help="host IP address")
parser.add_argument("-p", "--port", help="port number to use [default is 80]", type=int, default=80)
parser.add_argument("-v", action="store_true", help="show all responses not just 200 OK")
args = parser.parse_args()
host = args.host
lst = args.file
port = args.port
try:
        f = open(lst, "r")
        for line in f:
                try:
                        sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
                except socket.error, msg:
                        print msg
                        sys.exit(2)
                try:
                        sock.connect((host,port))
                except socket.error, msg:
                        print msg
                        sys.exit(3)
                page = "/" + line.rstrip('\n')
                sock.send("GET %s HTTP/1.0\r\nHost: %s\r\n\r\n" % (page, host))
                data = sock.recv(25).split('\n')
                if not data[0].find('200') == -1:
                        print "%s - %s" % (page, data[0])
                sock.close()
        f.close()
except IOError:
        print "Error opening file"
        sys.exit(1)
sys.exit(0)

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s