From 5658e7f71888a29a268b5c71af6019377b048b9b Mon Sep 17 00:00:00 2001 From: Alexey Vazhnov Date: Sat, 8 Jan 2022 15:59:47 +0300 Subject: [PATCH] =?UTF-8?q?=5Finternet=5Fon:=20try=20IPv4,=20if=20not=20ac?= =?UTF-8?q?ceptable=20=E2=80=94=20try=20IPv6=20(#4151)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * _internet_on: try IPv4, if not acceptable — try IPv6 * _internet_on: replace IPv4 `socket.socket` + IPv6 `socket.socket` with one universal `socket.create_connection` --- platformio/clients/http.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/platformio/clients/http.py b/platformio/clients/http.py index 7c20ba50..3cf247b4 100644 --- a/platformio/clients/http.py +++ b/platformio/clients/http.py @@ -196,8 +196,9 @@ def _internet_on(): continue requests.get("http://%s" % host, allow_redirects=False, timeout=timeout) return True - s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) - s.connect((host, 80)) + # try to resolve `host` for both AF_INET and AF_INET6, and then try to connect + # to all possible addresses (IPv4 and IPv6) in turn until a connection succeeds: + s = socket.create_connection((host, 80)) s.close() return True except: # pylint: disable=bare-except