switch_global.py 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. import httpx
  2. # base_url_list = [
  3. # "http://192.168.31.201:58001",
  4. # "http://192.168.31.201:58002",
  5. # "http://192.168.31.201:58003",
  6. # "http://192.168.31.201:58004",
  7. # "http://192.168.31.201:58005",
  8. # "http://192.168.31.201:58006",
  9. # "http://192.168.31.201:58007",
  10. # "http://192.168.31.201:58008",
  11. # "http://192.168.31.201:58009",
  12. # "http://192.168.31.201:58010",
  13. # ]
  14. base_url_list = [
  15. "http://192.168.64.32:58001",
  16. "http://192.168.64.32:58002",
  17. "http://192.168.64.32:58003",
  18. "http://192.168.64.32:58004",
  19. "http://192.168.64.32:58005",
  20. "http://192.168.64.32:58006",
  21. "http://192.168.64.32:58007",
  22. "http://192.168.64.32:58008",
  23. "http://192.168.64.32:58009",
  24. "http://192.168.64.32:58010",
  25. "http://192.168.64.32:58011",
  26. "http://192.168.64.32:58012",
  27. ]
  28. for base_url in base_url_list:
  29. key = "/api/configs"
  30. url = base_url + key
  31. headers = {
  32. "accept": "application/json, text/plain, */*",
  33. "accept-encoding": "gzip, deflate, br, zstd",
  34. "accept-language": "zh-CN,zh",
  35. "connection": "keep-alive",
  36. "content-type": "application/json",
  37. "host": "localhost:17888",
  38. "origin": base_url,
  39. "referer": base_url,
  40. "sec-ch-ua": '"Not A(Brand";v="8", "Chromium";v="132", "Brave";v="132"',
  41. "sec-ch-ua-mobile": "?0",
  42. "sec-ch-ua-platform": '"macOS"',
  43. "sec-fetch-dest": "empty",
  44. "sec-fetch-mode": "cors",
  45. "sec-fetch-site": "same-origin",
  46. "sec-gpc": "1",
  47. "user-agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/132.0.0.0 Safari/537.36",
  48. }
  49. # 请求体数据
  50. data = {"mode": "Global"} # 替换为实际的请求数据
  51. # 使用 httpx 发送 PATCH 请求
  52. try:
  53. with httpx.Client() as client:
  54. response = client.patch(url, headers=headers, json=data)
  55. if response.status_code == 204:
  56. print(f"{url} OK")
  57. else:
  58. print("响应内容:", response.text)
  59. except httpx.RequestError as exc:
  60. print(f"请求失败: {exc}")