File size: 1,105 Bytes
1fa9a79
 
 
98f37e9
1fa9a79
 
 
2a6b17e
92d4400
 
 
 
 
1fa9a79
 
 
 
 
 
 
 
 
92d4400
a287230
 
1fa9a79
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26

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)
        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查询频率受限"
        print(result)
        return result
    except:
        result = f"代理配置 {proxies_https}, 代理所在地查询超时,代理可能无效"
        print(result)
        return result


if __name__ == '__main__':
    import os; os.environ['no_proxy'] = '*' # 避免代理网络产生意外污染
    try: from config_private import proxies # 放自己的秘密如API和代理网址 os.path.exists('config_private.py')
    except: from config import proxies
    check_proxy(proxies)