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.
39 lines
1.2 KiB
39 lines
1.2 KiB
# -*- coding: utf-8 -*-
|
|
# 所有节点切换为全局
|
|
import asyncio
|
|
import httpx
|
|
|
|
async def set_global(url_and_port):
|
|
url = f"http://{url_and_port}"
|
|
key = "/api/configs"
|
|
full_url = url + key
|
|
|
|
data = {"mode": "Global"}
|
|
headers = {"Content-Type": "application/json"}
|
|
|
|
async with httpx.AsyncClient(timeout=10.0) as client:
|
|
try:
|
|
response = await client.patch(full_url, json=data, headers=headers)
|
|
response.raise_for_status() # 自动抛出4xx/5xx异常
|
|
print(f"成功设置 {url_and_port}")
|
|
return True
|
|
except httpx.HTTPError as exc:
|
|
print(f"请求失败 {url_and_port}: {exc}")
|
|
return False
|
|
|
|
async def main():
|
|
ip = '192.168.31.201'
|
|
port_list = [f'{58000 + i}' for i in range(1, 11)] # 生成端口列表
|
|
|
|
# 创建任务列表
|
|
tasks = [set_global(f"{ip}:{port}") for port in port_list]
|
|
|
|
# 并发执行所有任务
|
|
results = await asyncio.gather(*tasks)
|
|
|
|
# 统计结果
|
|
success_count = sum(results)
|
|
print(f"\n完成设置: {success_count}/{len(port_list)} 个代理成功")
|
|
|
|
if __name__ == "__main__":
|
|
asyncio.run(main()) |