You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
43 lines
1.1 KiB
43 lines
1.1 KiB
# -*- coding: utf-8 -*-
|
|
# 修改当前代理设置, 切换全局代理
|
|
|
|
import httpx
|
|
import asyncio
|
|
|
|
ip = "192.168.31.201"
|
|
|
|
select_port_list = 0
|
|
|
|
port_group_list = [
|
|
['58001', '58002', '58003', '58004', '58005', '58006', '58007', '58008', '58009', '58010'],
|
|
['32001', '32002', '32003', '32004', '32005', '32006', '32007', '32008', '32009', '32010', '32011', '32012']
|
|
]
|
|
|
|
port_list = port_group_list[select_port_list]
|
|
|
|
|
|
async def patch_config(base_port):
|
|
url_and_port = f"http://{ip}:{base_port}"
|
|
key = "/api/configs"
|
|
full_url = url_and_port + key
|
|
|
|
data = {"mode": "Global"}
|
|
headers = {"Content-Type": "application/json"}
|
|
|
|
async with httpx.AsyncClient() as client:
|
|
try:
|
|
response = await client.patch(full_url, json=data, headers=headers)
|
|
response.raise_for_status()
|
|
print(f"{url_and_port}: 切换全局代理 OK")
|
|
except httpx.HTTPError as exc:
|
|
print(f"请求失败: {exc}")
|
|
exit(1)
|
|
|
|
|
|
async def main():
|
|
tasks = [patch_config(base_port) for base_port in port_list]
|
|
await asyncio.gather(*tasks)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
asyncio.run(main())
|
|
|