Improve detecting of active Internet connection // Resolve #3359

This commit is contained in:
Ivan Kravets
2020-01-29 18:54:30 +02:00
parent 139171a79f
commit 607e8eb477
2 changed files with 11 additions and 9 deletions

View File

@ -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

View File

@ -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):