python check internet connection
import urllib.request
def internet_on():
try:
urllib.request.urlopen('http://216.58.192.142', timeout=2)
return True
except:
return False
3.83
6
import urllib2
def internet_on():
try:
urllib2.urlopen('http://216.58.192.142', timeout=1)
return True
except urllib2.URLError as err:
return False
Thank you!
6
0
Are there any code examples left?
New code examples in category Python