Secure HTTPS test internet is connected.

This commit is contained in:
Chris Coleman 2017-05-04 12:34:20 -04:00 committed by GitHub
parent f669b3ea2f
commit d84455ddae
1 changed files with 19 additions and 0 deletions

View File

@ -0,0 +1,19 @@
#!/usr/bin/env python
import urllib3
import certifi
def isInternetConnected(url="www.ietf.org"):
result = False
http = urllib3.PoolManager(
cert_reqs='CERT_REQUIRED', # Force certificate check.
ca_certs=certifi.where(), # Path to the Certifi bundle.
)
try:
r = http.request('HEAD', 'https://' + url)
result = True
except Exception as e: # urllib3.exceptions.SSLError
result = False
return result
print isInternetConnected()