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

75 lines
2.2 KiB
Python

#!/usr/bin/env python3
import sys
import time
import httpx
import paramiko
sys.stdout.reconfigure(encoding="utf-8", errors="replace", line_buffering=True)
def sh(port, user, pw, cmd, t=50):
print(f"## {user}@{port}", flush=True)
c = paramiko.SSHClient()
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
c.connect(
"107.173.30.245",
port,
user,
pw,
timeout=25,
banner_timeout=40,
allow_agent=False,
look_for_keys=False,
)
print("connected", flush=True)
print("$", cmd[:200], 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)
c.close()
sh(
4014,
"eric",
"4669805",
"echo 4669805 | sudo -S -p '' bash -lc '"
"ss -lntp | grep -E \":(8014|4015)\"; "
"ip addr show wg-dy; "
"ip route | head -20; "
"curl -sS -m 5 -o /dev/null -w local=%{http_code}\\\\n http://127.0.0.1:8014/api/health; "
"curl -sS -m 5 -o /dev/null -w via_self=%{http_code}\\\\n http://10.8.0.2:8014/api/health; "
"wg show; "
"sudo iptables -L INPUT -n | head -25"
"'",
)
sh(
22,
"root",
"Xiao4669805",
"wg show wg-dy; "
"ping -c 2 -W 2 10.8.0.2 | tail -4; "
"curl -sS -m 8 -o /dev/null -w via_wg=%{http_code}\\\\n http://10.8.0.2:8014/api/health; "
"curl -sS -m 8 -o /dev/null -w via_wg_web=%{http_code}\\\\n http://10.8.0.2:4015/; "
"iptables -L INPUT -n | grep 51820 || true",
)
with httpx.Client(follow_redirects=False, timeout=12) as cl:
for u in ["https://dy.nomadro.com/api/health", "https://dylive.nomadro.com/api/health"]:
try:
print(u, cl.get(u).status_code, flush=True)
except Exception as ex:
print(u, ex, flush=True)
print("DONE", flush=True)