add additonal source for checking proxy ip
This commit is contained in:
parent
e08bd9669e
commit
19ef6a530a
@ -3,15 +3,18 @@ def check_proxy(proxies):
|
|||||||
import requests
|
import requests
|
||||||
proxies_https = proxies['https'] if proxies is not None else '无'
|
proxies_https = proxies['https'] if proxies is not None else '无'
|
||||||
try:
|
try:
|
||||||
response = requests.get("https://ipapi.co/json/",
|
response = requests.get("https://ipapi.co/json/", proxies=proxies, timeout=4)
|
||||||
proxies=proxies, timeout=4)
|
|
||||||
data = response.json()
|
data = response.json()
|
||||||
print(f'查询代理的地理位置,返回的结果是{data}')
|
print(f'查询代理的地理位置,返回的结果是{data}')
|
||||||
if 'country_name' in data:
|
if 'country_name' in data:
|
||||||
country = data['country_name']
|
country = data['country_name']
|
||||||
result = f"代理配置 {proxies_https}, 代理所在地:{country}"
|
result = f"代理配置 {proxies_https}, 代理所在地:{country}"
|
||||||
elif 'error' in data:
|
elif 'error' in data:
|
||||||
|
alternative = _check_with_backup_source(proxies)
|
||||||
|
if alternative is None:
|
||||||
result = f"代理配置 {proxies_https}, 代理所在地:未知,IP查询频率受限"
|
result = f"代理配置 {proxies_https}, 代理所在地:未知,IP查询频率受限"
|
||||||
|
else:
|
||||||
|
result = f"代理配置 {proxies_https}, 代理所在地:{alternative}"
|
||||||
else:
|
else:
|
||||||
result = f"代理配置 {proxies_https}, 代理数据解析失败:{data}"
|
result = f"代理配置 {proxies_https}, 代理数据解析失败:{data}"
|
||||||
print(result)
|
print(result)
|
||||||
@ -21,6 +24,11 @@ def check_proxy(proxies):
|
|||||||
print(result)
|
print(result)
|
||||||
return 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):
|
def backup_and_download(current_version, remote_version):
|
||||||
"""
|
"""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user