Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def get_connection_status(remote_server = "www.google.com"):
- for timeout in [1, 5, 10, 15]:
- try:
- print "Checking internet connection.."
- socket.setdefaulttimeout(timeout)
- # see if we can resolve the host name -- tells us if there is
- # a DNS listening
- host = socket.gethostbyname(remote_server)
- # connect to the host -- tells us if the host is actually
- # reachable
- s = socket.create_connection((host, 80), 2)
- s.close()
- print 'Internet connected.'
- return "Connected"
- except Exception, e:
- print e
- print "Internet not connected."
- return "Not Connected"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement