mirror of
https://github.com/platformio/platformio-core.git
synced 2025-07-30 10:07:14 +02:00
Improve detecting of active Internet connection // Resolve #3359
This commit is contained in:
@ -366,10 +366,11 @@ def get_api_result(url, params=None, data=None, auth=None, cache_valid=None):
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
PING_INTERNET_IPS = [
|
PING_REMOTE_HOSTS = [
|
||||||
"192.30.253.113", # github.com
|
"140.82.118.3", # Github.com
|
||||||
"78.46.220.20", # api.platformio.org
|
"35.231.145.151", # Gitlab.com
|
||||||
"3.124.149.187", # registry.platformio.org
|
"github.com",
|
||||||
|
"platformio.org",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
@ -377,12 +378,13 @@ PING_INTERNET_IPS = [
|
|||||||
def _internet_on():
|
def _internet_on():
|
||||||
timeout = 2
|
timeout = 2
|
||||||
socket.setdefaulttimeout(timeout)
|
socket.setdefaulttimeout(timeout)
|
||||||
for ip in PING_INTERNET_IPS:
|
for host in PING_REMOTE_HOSTS:
|
||||||
try:
|
try:
|
||||||
if os.getenv("HTTP_PROXY", os.getenv("HTTPS_PROXY")):
|
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:
|
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
|
return True
|
||||||
except: # pylint: disable=bare-except
|
except: # pylint: disable=bare-except
|
||||||
pass
|
pass
|
||||||
|
@ -25,8 +25,8 @@ def test_platformio_cli():
|
|||||||
|
|
||||||
|
|
||||||
def test_ping_internet_ips():
|
def test_ping_internet_ips():
|
||||||
for ip in util.PING_INTERNET_IPS:
|
for host in util.PING_REMOTE_HOSTS:
|
||||||
requests.get("http://%s" % ip, allow_redirects=False, timeout=2)
|
requests.get("http://%s" % host, allow_redirects=False, timeout=2)
|
||||||
|
|
||||||
|
|
||||||
def test_api_internet_offline(without_internet, isolated_pio_home):
|
def test_api_internet_offline(without_internet, isolated_pio_home):
|
||||||
|
Reference in New Issue
Block a user