From 99b06ef47ef09198c9217fcec6d1b7b1d8138a27 Mon Sep 17 00:00:00 2001 From: Chris Coleman Date: Thu, 4 May 2017 12:34:20 -0400 Subject: [PATCH] Secure HTTPS test internet is connected. Signed-off-by: Nicolas Sebrecht --- contrib/internet-urllib3.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 contrib/internet-urllib3.py diff --git a/contrib/internet-urllib3.py b/contrib/internet-urllib3.py new file mode 100644 index 0000000..13fc72c --- /dev/null +++ b/contrib/internet-urllib3.py @@ -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()