Advertisement
python_notes

Check for internet connectivity

Aug 15th, 2014
497
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.60 KB | None | 0 0
  1. # Check for internet connectivity:
  2.  
  3. #Example 1
  4.  
  5. import sys, time, urllib2
  6.  
  7. print ("Checking internet activity")
  8. time.sleep (3.0)
  9. try:
  10.     con = urllib2.urlopen('http://www.google.com/')
  11.     data = con.read()
  12.     print 'Checking for internet connectivity please wait ...'
  13.     print 'Internet connectivity ... OK!'
  14.     print 'Starting update script!'
  15. except:
  16.     print 'No internet :('
  17.     sys.exit()
  18.  
  19.  
  20.  
  21.  
  22. #Example 2
  23.  
  24. #!/usr/bin/python2
  25.  
  26. import urllib
  27. try :
  28.     stri = "https://www.google.com"
  29.     data = urllib.urlopen(stri)
  30.     print "Connectivity to www found"
  31. except e:
  32.     print "not connected" ,e
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement