douyinWEB/scripts/_diag_hysteria5_ping.py
2026-09-13 22:10:49 -05:00

80 lines
3.0 KiB
Python

#!/usr/bin/env python3
"""Diagnose why 1d2da142-singbox_hysteria5 is not pingable. Live flush."""
from __future__ import annotations
import json
import sys
import time
import paramiko
sys.stdout.reconfigure(encoding="utf-8", errors="replace", line_buffering=True)
HOST = "107.173.30.245"
NEEDLE = "1d2da142"
NEEDLE2 = "hysteria5"
def connect(port=22, user="root", pw="Xiao4669805"):
c = paramiko.SSHClient()
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
c.connect(HOST, port, user, pw, timeout=25, banner_timeout=40, allow_agent=False, look_for_keys=False)
print(f"connected :{port}", flush=True)
return c
def run(c, cmd, t=60):
print(f"\n$ {cmd[:220]}", flush=True)
_i, o, e = c.exec_command(cmd, timeout=t)
while not o.channel.exit_status_ready():
if o.channel.recv_ready():
sys.stdout.write(o.channel.recv(4096).decode("utf-8", "replace"))
sys.stdout.flush()
if o.channel.recv_stderr_ready():
sys.stdout.write(o.channel.recv_stderr(4096).decode("utf-8", "replace"))
sys.stdout.flush()
time.sleep(0.1)
sys.stdout.write((o.read() + e.read()).decode("utf-8", "replace"))
sys.stdout.flush()
print("->", o.channel.recv_exit_status(), flush=True)
print("## VPS sing-box + configs mentioning node", flush=True)
v = connect(22)
run(v, "systemctl is-active sing-box; systemctl status sing-box --no-pager -l | head -25")
run(
v,
f"find /etc /opt /root /usr -maxdepth 4 \\( -name '*sing*' -o -name '*hysteria*' -o -name 'config.json' \\) 2>/dev/null | head -40; "
f"grep -Rsn --include='*.json' --include='*.yaml' --include='*.yml' --include='*.toml' "
f"-e '{NEEDLE}' -e '{NEEDLE2}' -e 'singbox_hysteria' /etc /opt /root 2>/dev/null | head -40",
t=90,
)
run(
v,
# common sing-box clash API / experimental
"ss -lntp | grep -iE 'sing|2080|2090|9090|9091|7890|1080' || true; "
"command -v sing-box; sing-box version 2>/dev/null | head -5; "
"ls /etc/sing-box 2>/dev/null; ls /etc/sing-box/ 2>/dev/null",
)
v.close()
print("## physical ShellCrash proxies (via FRP)", flush=True)
g = connect(4014, "eric", "4669805")
run(
g,
"echo 4669805 | sudo -S -p '' bash -lc '"
f"grep -Rsn --include=\"*.yaml\" --include=\"*.yml\" --include=\"*.json\" -e \"{NEEDLE}\" -e \"{NEEDLE2}\" "
f"/etc/ShellCrash /tmp/ShellCrash 2>/dev/null | head -40; "
"curl -sS -m 8 http://127.0.0.1:9999/proxies 2>/dev/null | python3 -c "
"\"import sys,json; d=json.load(sys.stdin); ps=d.get(\\\"proxies\\\") or d; "
"keys=[k for k in (ps if isinstance(ps,dict) else {}) if \\\"hysteria\\\" in k.lower() or \\\"1d2da\\\" in k.lower()]; "
"print(\\\"match_keys\\\", keys[:30]); "
"[print(k, (ps.get(k)||{}).get(\\\"type\\\"), (ps.get(k)||{}).get(\\\"history\\\",[{}])[-1] if (ps.get(k)||{}).get(\\\"history\\\") else None) for k in keys[:15]]\" "
"2>/dev/null || echo no_clash_api; "
"curl -sS -m 5 http://127.0.0.1:9999/version; echo"
"'",
t=50,
)
g.close()
print("DONE", flush=True)