Test IPs which used for testing internet connection

This commit is contained in:
Ivan Kravets
2017-12-14 20:18:19 +02:00
parent 70b63d8618
commit ef00ecd7f1
2 changed files with 28 additions and 5 deletions

View File

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

21
tests/test_misc.py Normal file
View File

@ -0,0 +1,21 @@
# Copyright (c) 2014-present PlatformIO <contact@platformio.org>
#
# 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)