#!/usr/bin/env python3 # -*- coding: utf-8 -*- """Probe WG on overseas VPS, domestic Tencent, and physical guest.""" from __future__ import annotations import sys import time import paramiko if hasattr(sys.stdout, "reconfigure"): sys.stdout.reconfigure(encoding="utf-8", errors="replace") OVERSEAS = "107.173.30.245" DOMESTIC = "82.157.112.245" DOMESTIC_USER = "ubuntu" DOMESTIC_PASS = "Xiao4669805" OVERSEAS_PASS = "Xiao4669805" GUEST_PASS = "4669805" def ssh(host, port, user, pw, tries=5): last = None for i in range(tries): try: c = paramiko.SSHClient() c.set_missing_host_key_policy(paramiko.AutoAddPolicy()) c.connect(host, port, user, pw, timeout=40, banner_timeout=80, allow_agent=False, look_for_keys=False) return c except Exception as ex: last = ex print(f"ssh {host}:{port} try{i} {type(ex).__name__}: {ex}", flush=True) time.sleep(2) raise last # type: ignore[misc] def run(c, cmd, timeout=60): _, o, e = c.exec_command(cmd, timeout=timeout) return (o.read() + e.read()).decode("utf-8", "replace") WG_PROBE = r"""set -uo pipefail echo '--- hostname / ip ---' hostname; curl -sS -m 3 https://api.ipify.org 2>/dev/null; echo echo '--- wg interfaces ---' ip -br a | grep -E 'wg|tun' || echo '(none)' wg show 2>/dev/null || echo 'wg not installed' echo '--- wg configs ---' ls -la /etc/wireguard/ 2>/dev/null || echo 'no /etc/wireguard' for f in /etc/wireguard/*.conf; do [ -f "$f" ] || continue echo "== $f ==" grep -E '^\[|Address|ListenPort|Endpoint|AllowedIPs|PublicKey' "$f" | head -20 done echo '--- routes ---' ip route | head -12 echo '--- listen udp ---' ss -ulnp | grep -E '5182|5183' || true echo '--- forward ---' sysctl net.ipv4.ip_forward 2>/dev/null || true """ def main(): v = ssh(OVERSEAS, 22, "root", OVERSEAS_PASS) extra_vps = r""" echo '--- caddy dy upstream ---' grep -E '10\.8\.0\.|10\.9\.0\.|reverse_proxy' /etc/caddy/sites/dy.nomadro.com.caddy 2>/dev/null | head -25 echo '--- ping physical ---' ping -c 2 -W 2 10.8.0.2 2>&1 | tail -3 """ print("\n===== OVERSEAS VPS =====", flush=True) print(run(v, WG_PROBE + extra_vps, 90), flush=True) v.close() try: d = ssh(DOMESTIC, 22, DOMESTIC_USER, DOMESTIC_PASS) extra_dom = r""" echo '--- douyinweb? ---' ls /opt/douyinWEB 2>/dev/null | head -5 || echo 'no app' systemctl list-units --type=service 2>/dev/null | grep -iE 'douyin|wg|caddy' || true """ print("\n===== DOMESTIC TENCENT =====", flush=True) print(run(d, WG_PROBE + extra_dom, 90), flush=True) d.close() except Exception as ex: print(f"DOMESTIC unreachable: {ex}", flush=True) try: g = ssh(OVERSEAS, 4014, "eric", GUEST_PASS) guest_script = ( f"echo '{GUEST_PASS}' | sudo -S -p '' bash -lc " f"\"{WG_PROBE.replace(chr(10), '; ')}; " "ping -c 2 -W 2 10.8.0.1 2>&1 | tail -3; " "curl -sS -m 3 -o /dev/null -w 'local_api=%{http_code}\\n' http://127.0.0.1:8014/api/health\"" ) print("\n===== PHYSICAL GUEST =====", flush=True) print(run(g, guest_script, 90), flush=True) g.close() except Exception as ex: print(f"PHYSICAL unreachable: {ex}", flush=True) if __name__ == "__main__": main()