From 607e8eb477ddebf1b0876ca6ec6d734f5e16915a Mon Sep 17 00:00:00 2001 From: Ivan Kravets Date: Wed, 29 Jan 2020 18:54:30 +0200 Subject: [PATCH] Improve detecting of active Internet connection // Resolve #3359 --- platformio/util.py | 16 +++++++++------- tests/test_misc.py | 4 ++-- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/platformio/util.py b/platformio/util.py index 640295d2..f9c304f9 100644 --- a/platformio/util.py +++ b/platformio/util.py @@ -366,10 +366,11 @@ def get_api_result(url, params=None, data=None, auth=None, cache_valid=None): ) -PING_INTERNET_IPS = [ - "192.30.253.113", # github.com - "78.46.220.20", # api.platformio.org - "3.124.149.187", # registry.platformio.org +PING_REMOTE_HOSTS = [ + "140.82.118.3", # Github.com + "35.231.145.151", # Gitlab.com + "github.com", + "platformio.org", ] @@ -377,12 +378,13 @@ PING_INTERNET_IPS = [ def _internet_on(): timeout = 2 socket.setdefaulttimeout(timeout) - for ip in PING_INTERNET_IPS: + for host in PING_REMOTE_HOSTS: try: if os.getenv("HTTP_PROXY", os.getenv("HTTPS_PROXY")): - requests.get("http://%s" % ip, allow_redirects=False, timeout=timeout) + requests.get("http://%s" % host, allow_redirects=False, timeout=timeout) else: - socket.socket(socket.AF_INET, socket.SOCK_STREAM).connect((ip, 80)) + + socket.socket(socket.AF_INET, socket.SOCK_STREAM).connect((host, 80)) return True except: # pylint: disable=bare-except pass diff --git a/tests/test_misc.py b/tests/test_misc.py index 1a1c7c32..aee9f113 100644 --- a/tests/test_misc.py +++ b/tests/test_misc.py @@ -25,8 +25,8 @@ def test_platformio_cli(): def test_ping_internet_ips(): - for ip in util.PING_INTERNET_IPS: - requests.get("http://%s" % ip, allow_redirects=False, timeout=2) + for host in util.PING_REMOTE_HOSTS: + requests.get("http://%s" % host, allow_redirects=False, timeout=2) def test_api_internet_offline(without_internet, isolated_pio_home):