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

97 lines
2.7 KiB
Python

#!/usr/bin/env python3
"""Fix wg-dy handshake only. No Neko. Live flush."""
from __future__ import annotations
import sys
import time
import httpx
import paramiko
sys.stdout.reconfigure(encoding="utf-8", errors="replace", line_buffering=True)
def connect(port=22, user="root", pw="Xiao4669805"):
for i in range(10):
try:
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(f"connected :{port}", flush=True)
return c
except Exception as ex:
print(f"retry :{port} {i} {ex}", flush=True)
time.sleep(2)
raise RuntimeError("ssh fail")
def run(c, cmd, t=60):
print(f"$ {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(f"→ {o.channel.recv_exit_status()}", flush=True)
print("## VPS wg bounce", flush=True)
v = connect(22)
run(
v,
"wg-quick down wg-dy; wg-quick up wg-dy; sleep 1; "
"wg show wg-dy; "
"ss -ulnp | grep 51820 || true",
)
v.close()
print("## guest wg bounce", flush=True)
g = connect(4014, "eric", "4669805")
run(
g,
"echo 4669805 | sudo -S -p '' bash -lc '"
"wg-quick down wg-dy; wg-quick up wg-dy; sleep 2; "
"wg show wg-dy; "
"ping -c 3 -W 2 10.8.0.1 | tail -5"
"'",
t=50,
)
g.close()
print("## wait handshake 8s", flush=True)
time.sleep(8)
v = connect(22)
run(
v,
"wg show wg-dy; ping -c 3 -W 2 10.8.0.2 | tail -5; "
"curl -sS -m 10 -o /dev/null -w 'via_wg=%{http_code}\\n' http://10.8.0.2:8014/api/health",
t=40,
)
v.close()
print("## public", flush=True)
with httpx.Client(follow_redirects=False, timeout=15) as cl:
for u in ["https://dy.nomadro.com/api/health", "https://dy.nomadro.com/", "https://dylive.nomadro.com/api/health"]:
try:
r = cl.get(u)
print(f"{u} -> {r.status_code}", flush=True)
except Exception as ex:
print(f"{u} ERR {ex}", flush=True)
print("DONE", flush=True)