internet-urllib3.py 462 B

12345678910111213141516171819
  1. #!/usr/bin/env python
  2. import urllib3
  3. import certifi
  4. def isInternetConnected(url="www.ietf.org"):
  5. result = False
  6. http = urllib3.PoolManager(
  7. cert_reqs='CERT_REQUIRED', # Force certificate check.
  8. ca_certs=certifi.where(), # Path to the Certifi bundle.
  9. )
  10. try:
  11. r = http.request('HEAD', 'https://' + url)
  12. result = True
  13. except Exception as e: # urllib3.exceptions.SSLError
  14. result = False
  15. return result
  16. print(isInternetConnected())