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

86 lines
3.2 KiB
Python

#!/usr/bin/env python3
"""Deep check hysteria5: DNS, UDP ports, Clash delay, sing-box inbound."""
from __future__ import annotations
import sys
import time
import urllib.parse
import paramiko
sys.stdout.reconfigure(encoding="utf-8", errors="replace", line_buffering=True)
HOST = "107.173.30.245"
NODE = "1d2da142-singbox_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=70):
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 hysteria inbound", flush=True)
v = connect(22)
run(
v,
"python3 - <<'PY'\n"
"import json\n"
"p='/etc/v2ray-agent/sing-box/conf/config.json'\n"
"d=json.load(open(p))\n"
"for ib in d.get('inbounds') or []:\n"
" t=ib.get('type') or ''\n"
" tag=ib.get('tag') or ''\n"
" listen=ib.get('listen')\n"
" port=ib.get('listen_port') or ib.get('port')\n"
" if 'hysteria' in t.lower() or 'hysteria' in tag.lower() or 'tuic' in t.lower():\n"
" print(tag, t, listen, port)\n"
" # print users tags\n"
" users=(ib.get('users') or [])[:3]\n"
" for u in users:\n"
" print(' user', {k:u.get(k) for k in ('name','uuid','password') if k in u})\n"
"print('--- udp listen ---')\n"
"PY\n"
"ss -ulnp | grep -E 'sing|21825|30000|16113|32000' | head -30; "
"getent hosts specials.nomadro.live; dig +short specials.nomadro.live A 2>/dev/null | head -5",
t=40,
)
v.close()
print("## physical: DNS + delay test via Clash API", flush=True)
g = connect(4014, "eric", "4669805")
q = urllib.parse.quote(NODE, safe="")
run(
g,
"echo 4669805 | sudo -S -p '' bash -lc '"
"getent hosts specials.nomadro.live; "
"dig +short specials.nomadro.live A 2>/dev/null | head -5; "
"timeout 3 bash -c \"echo >/dev/udp/specials.nomadro.live/21825\" 2>/dev/null && echo udp21825_send_ok || echo udp21825_send_fail; "
f"curl -sS -m 15 -X GET \"http://127.0.0.1:9999/proxies/{q}/delay?timeout=5000&url=http://www.gstatic.com/generate_204\"; echo; "
f"curl -sS -m 8 \"http://127.0.0.1:9999/proxies/{q}\" | python3 -m json.tool 2>/dev/null | head -60; "
"curl -sS -m 12 -X GET \"http://127.0.0.1:9999/proxies/1d2da142-singbox_tuic5/delay?timeout=5000&url=http://www.gstatic.com/generate_204\"; echo; "
"curl -sS -m 12 -X GET \"http://127.0.0.1:9999/proxies/1d2da142-VLESS_Reality_Vision5/delay?timeout=5000&url=http://www.gstatic.com/generate_204\"; echo"
"'",
t=80,
)
g.close()
print("DONE", flush=True)