Skip to content

Commit

Permalink
add additonal source for checking proxy ip
Browse files Browse the repository at this point in the history
  • Loading branch information
binary-husky committed Jul 30, 2023
1 parent e08bd96 commit 19ef6a5
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions check_proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,18 @@ def check_proxy(proxies):
import requests
proxies_https = proxies['https'] if proxies is not None else '无'
try:
response = requests.get("https://ipapi.co/json/",
proxies=proxies, timeout=4)
response = requests.get("https://ipapi.co/json/", proxies=proxies, timeout=4)
data = response.json()
print(f'查询代理的地理位置,返回的结果是{data}')
if 'country_name' in data:
country = data['country_name']
result = f"代理配置 {proxies_https}, 代理所在地:{country}"
elif 'error' in data:
result = f"代理配置 {proxies_https}, 代理所在地:未知,IP查询频率受限"
alternative = _check_with_backup_source(proxies)
if alternative is None:
result = f"代理配置 {proxies_https}, 代理所在地:未知,IP查询频率受限"
else:
result = f"代理配置 {proxies_https}, 代理所在地:{alternative}"
else:
result = f"代理配置 {proxies_https}, 代理数据解析失败:{data}"
print(result)
Expand All @@ -21,6 +24,11 @@ def check_proxy(proxies):
print(result)
return result

def _check_with_backup_source(proxies):
import random, string, requests
random_string = ''.join(random.choices(string.ascii_letters + string.digits, k=32))
try: return requests.get(f"http://{random_string}.edns.ip-api.com/json", proxies=proxies, timeout=4).json()['dns']['geo']
except: return None

def backup_and_download(current_version, remote_version):
"""
Expand Down

0 comments on commit 19ef6a5

Please sign in to comment.