| 123456789101112131415161718192021222324252627282930313233343536 |
- # -*- coding: utf-8 -*-
- # 修改当前代理设置, 切换全局代理
- import httpx
- import asyncio
- ip = "192.168.31.201"
- port_list = ['58001', '58002', '58003', '58004', '58005', '58006', '58007', '58008', '58009', '58010']
- # port_list = ['32001', '32002', '32003', '32004', '32005', '32006', '32007', '32008', '32009', '32010', '32011', '32012']
- 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())
|