wtorek, 1 października 2013

check page access code status and report possible errors

#!/usr/bin/python
import os
def line():
    print '-' *50
import urllib2
import time

try:
    hosts = ["http://www.google.pl","http://www.opitz-consulting.com","http://www.facebook.com"]
    for key in hosts:
   
        req = urllib2.Request(key)
        response = urllib2.urlopen(req)
        print key
        print response.getcode()
        code = response.getcode()
        if code == 200:
            print "ok"
        elif code != 200:
            print "warning"
        print response.read(200)
        line()
   
except:
     print "oppps something goes wrong check the network connection\n\n"
     network = os.popen("ifconfig wlan0 && ifconfig eth0").read()
     print network
 

Brak komentarzy:

Prześlij komentarz