|
|
@@ -1,79 +0,0 @@
|
|
|
-from nicegui import ui
|
|
|
-import httpx
|
|
|
-
|
|
|
-async def check_now_node(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() as client:
|
|
|
- try:
|
|
|
- response = await client.patch(full_url, json=data, headers=headers)
|
|
|
- if response.status_code != 204:
|
|
|
- raise Exception(f"请求失败: {response.status_code}")
|
|
|
- except httpx.HTTPError as exc:
|
|
|
- print(f"请求失败: {exc}")
|
|
|
- return None
|
|
|
-
|
|
|
- url_proxies = f"http://{url_and_port}/api/proxies"
|
|
|
- headers_proxies = {
|
|
|
- # 这里可以复用之前的headers
|
|
|
- "Accept": "application/json, text/plain, */*",
|
|
|
- "Host": url_and_port,
|
|
|
- # 其他可按需设置
|
|
|
- }
|
|
|
-
|
|
|
- try:
|
|
|
- response = await client.get(url_proxies, headers=headers_proxies)
|
|
|
- json_data = response.json()
|
|
|
- if not json_data or response.status_code != 200:
|
|
|
- print("JSON data is empty or request failed")
|
|
|
- return None
|
|
|
-
|
|
|
- proxies = json_data.get("proxies")
|
|
|
- proxy_global = proxies.get("GLOBAL")
|
|
|
- now_proxy = proxy_global.get("now")
|
|
|
-
|
|
|
- return now_proxy
|
|
|
- except httpx.RequestError as e:
|
|
|
- print(f"Request failed: {e}")
|
|
|
- return None
|
|
|
-
|
|
|
-async def handle_check_now_node():
|
|
|
- ip = '192.168.31.201'
|
|
|
- port_list = ['58001', '58002', '58003', '58004', '58005', '58006', '58007', '58008', '58009', '58010']
|
|
|
- results = []
|
|
|
-
|
|
|
- for port in port_list:
|
|
|
- url_and_port = f"{ip}:{port}"
|
|
|
- now_proxy = await check_now_node(url_and_port)
|
|
|
- results.append(f"{url_and_port}: \t{now_proxy}")
|
|
|
-
|
|
|
- msg = "\n".join(results)
|
|
|
- print(msg)
|
|
|
-
|
|
|
- dialog = ui.dialog()
|
|
|
- with dialog:
|
|
|
- ui.label(msg).classes("whitespace-pre-wrap text-left")
|
|
|
-
|
|
|
- dialog.props("max-width=700px")
|
|
|
- dialog.open()
|
|
|
-
|
|
|
-def handle_switch_node():
|
|
|
- print("Switch IP button clicked")
|
|
|
-
|
|
|
-def main():
|
|
|
- with ui.row().classes("mx-auto"):
|
|
|
- ui.button("Check Now Node", on_click=handle_check_now_node).classes("mt-1")
|
|
|
- ui.button("Switch Node", on_click=handle_switch_node).classes("mt-1")
|
|
|
-
|
|
|
- ui.label("Filter Node").classes("text-lg font-bold text-blue-500 mt-4")
|
|
|
- ui.input(value="JP").classes("w-96")
|
|
|
-
|
|
|
- ui.run(port=48345)
|
|
|
-
|
|
|
-if __name__ in {"__main__", "__mp_main__"}:
|
|
|
- main()
|