# -*- coding: utf-8 -*- """Probe ShellCrash dashboard and switch to a working egress node.""" from __future__ import annotations import json import sys import httpx import paramiko sys.stdout.reconfigure(encoding="utf-8", errors="replace") GUEST_PW = "4669805" def main() -> int: c = paramiko.SSHClient() c.set_missing_host_key_policy(paramiko.AutoAddPolicy()) c.connect( "107.173.30.245", 4014, "eric", GUEST_PW, timeout=40, banner_timeout=80, allow_agent=False, look_for_keys=False, ) script = r""" # mihomo external controller curl -sS -m 3 http://127.0.0.1:9999/version || true echo curl -sS -m 5 http://127.0.0.1:9999/proxies | python3 -c 'import sys,json; d=json.load(sys.stdin); print("groups", [k for k,v in d.get("proxies",{}).items() if v.get("type") in ("Selector","URLTest","Fallback")]); g=d.get("proxies",{}).get("GLOBAL") or {}; print("GLOBAL", g.get("now"), "all", (g.get("all") or [])[:12])' 2>/dev/null || true # try put GLOBAL to DIRECT then a node for node in DIRECT socks5 proxycheap "242af835-singbox_hysteria" hackrobot-singbox_tuic; do echo "try GLOBAL -> $node" curl -sS -m 3 -X PUT http://127.0.0.1:9999/proxies/GLOBAL -H 'Content-Type: application/json' -d "{\"name\":\"$node\"}" || true echo code=$(curl -sS -m 8 -o /dev/null -w '%{http_code}' -x http://127.0.0.1:7890 https://www.google.com/generate_204 || echo fail) echo "mixed=$code" [ "$code" = "204" ] && break done # also SELECT if exists curl -sS -m 3 -X PUT http://127.0.0.1:9999/proxies/SELECT -H 'Content-Type: application/json' -d '{"name":"socks5"}' 2>/dev/null || true curl -sS -m 8 -o /dev/null -w 'after_select:%{http_code}\n' -x http://127.0.0.1:7890 https://www.google.com/generate_204 || echo after_select:fail systemctl is-active shellcrash wg-quick@wg-dy douyinweb-api curl -sS -m 3 -o /dev/null -w 'api:%{http_code}\n' http://127.0.0.1:8014/api/health """ sftp = c.open_sftp() with sftp.file("/tmp/_sc_probe.sh", "w") as f: f.write(script.replace("\r\n", "\n")) sftp.close() _, o, e = c.exec_command( f"echo '{GUEST_PW}' | sudo -S -p '' bash /tmp/_sc_probe.sh", timeout=120, ) print((o.read() + e.read()).decode("utf-8", "replace")) c.close() with httpx.Client(base_url="https://dy.nomadro.com", timeout=20.0) as client: client.post("/api/auth/login", json={"username": "hackrobot", "password": "Xiao4669805@"}) sc = (client.get("/api/network").json() or {}).get("shellcrash") or {} print("hub", {k: sc.get(k) for k in ("installed", "running", "unit", "mixed_port", "enabled")}) return 0 if __name__ == "__main__": raise SystemExit(main())