Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.72 KB | None | 0 0
  1. def get_connection_status(remote_server = "www.google.com"):
  2. for timeout in [1, 5, 10, 15]:
  3. try:
  4. print "Checking internet connection.."
  5. socket.setdefaulttimeout(timeout)
  6.  
  7. # see if we can resolve the host name -- tells us if there is
  8. # a DNS listening
  9. host = socket.gethostbyname(remote_server)
  10.  
  11. # connect to the host -- tells us if the host is actually
  12. # reachable
  13. s = socket.create_connection((host, 80), 2)
  14. s.close()
  15.  
  16. print 'Internet connected.'
  17. return "Connected"
  18. except Exception, e:
  19. print e
  20. print "Internet not connected."
  21. return "Not Connected"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement