65 lines
2.2 KiB
Python
65 lines
2.2 KiB
Python
import requests
|
|
import random
|
|
|
|
|
|
|
|
def change_proxy():
|
|
port = '17650'
|
|
secret = '7ce2f241-d6a1-4b69-a742-96201072187a'
|
|
selector = '🚀 节点选择'
|
|
|
|
port = port
|
|
secret = secret
|
|
|
|
headers_secret = {
|
|
'Authorization': 'Bearer {}'.format(secret)
|
|
}
|
|
|
|
url_all_proxies_info = 'http://127.0.0.1:{}/proxies'.format(port)
|
|
url_all_proxies_info = requests.get(url_all_proxies_info,headers=headers_secret).json()
|
|
url_all_proxies = 'http://127.0.0.1:{}/proxies/{}'.format(port,selector)
|
|
|
|
res_proxies = requests.get(url_all_proxies,headers=headers_secret).json()
|
|
# res_proxies = res_proxies['proxies'][selector]
|
|
proxy_name_list = res_proxies['all'][3:-3]
|
|
now_proxy = res_proxies['now']
|
|
print('现在的代理是{}'.format(now_proxy))
|
|
# if now_proxy not in ['DIRECT','REJECT','账号邮箱看最新的地址','NETV2','自动选择','故障转移']:
|
|
# proxy_name_list.remove(now_proxy)
|
|
|
|
shift = []
|
|
continue_proxys = ['♻️ 自动选择', '仅海外用户']
|
|
for proxy_name in proxy_name_list:
|
|
is_continue = False
|
|
for continue_proxy in continue_proxys:
|
|
if continue_proxy in proxy_name:
|
|
is_continue = True
|
|
break
|
|
if is_continue:
|
|
continue
|
|
# if '香港' not in proxy_name or '日本' not in proxy_name or '俄罗斯' not in proxy_name:
|
|
# continue
|
|
shift.append(proxy_name)
|
|
proxy_name_list = shift
|
|
|
|
while True:
|
|
random_proxy = random.choice(proxy_name_list)
|
|
delay = url_all_proxies_info['proxies'][random_proxy]['history'][-1]['delay']
|
|
if delay!=0:
|
|
break
|
|
print('随机选择的代理为{}'.format(random_proxy))
|
|
data = {
|
|
"name": random_proxy
|
|
}
|
|
headers = {
|
|
"content-type": "application/json",
|
|
'Authorization': 'Bearer {}'.format(secret)
|
|
}
|
|
|
|
res = requests.put(url=url_all_proxies,json=data,headers=headers)
|
|
print('切换代理请求的状态码为{}'.format(res.status_code))
|
|
if res.status_code == 204:
|
|
print('切换代理成功!现在的代理为{}'.format(random_proxy))
|
|
if __name__ == '__main__':
|
|
change_proxy()
|