From ef00ecd7f1aed7ccd555b841cf5b7ec36c1a0e81 Mon Sep 17 00:00:00 2001 From: Ivan Kravets Date: Thu, 14 Dec 2017 20:18:19 +0200 Subject: [PATCH] Test IPs which used for testing internet connection --- platformio/util.py | 12 +++++++----- tests/test_misc.py | 21 +++++++++++++++++++++ 2 files changed, 28 insertions(+), 5 deletions(-) create mode 100644 tests/test_misc.py diff --git a/platformio/util.py b/platformio/util.py index 80cd1858..cb78642e 100644 --- a/platformio/util.py +++ b/platformio/util.py @@ -575,15 +575,17 @@ def get_api_result(url, params=None, data=None, auth=None, cache_valid=None): "Please try later.") +PING_INTERNET_IPS = [ + "159.122.18.156", # dl.bintray.com + "193.222.52.25" # dl.platformio.org +] + + @memoized def _internet_on(): - ips = [ - "193.222.52.25", # dl.platformio.org - "159.122.18.156" # dl.bintray.com - ] timeout = 2 socket.setdefaulttimeout(timeout) - for ip in ips: + for ip in PING_INTERNET_IPS: try: if os.getenv("HTTP_PROXY", os.getenv("HTTPS_PROXY")): requests.get("http://%s" % ip, timeout=timeout) diff --git a/tests/test_misc.py b/tests/test_misc.py new file mode 100644 index 00000000..271a4858 --- /dev/null +++ b/tests/test_misc.py @@ -0,0 +1,21 @@ +# Copyright (c) 2014-present PlatformIO +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import requests +from platformio import util + + +def test_ping_internet_ips(): + for ip in util.PING_INTERNET_IPS: + requests.get("http://%s" % ip, timeout=2) \ No newline at end of file