Capture Neko/WG/network hubs, Studio viewer charts, physical deploy docs, and one-shot scripts so VPS vs physical can be toggled later without losing WIP. Co-authored-by: Cursor <cursoragent@cursor.com>
196 lines
6.2 KiB
Python
196 lines
6.2 KiB
Python
# -*- coding: utf-8 -*-
|
|
"""Diagnose Neko 5/6 loading forever (HTTP vs WebRTC)."""
|
|
from __future__ import annotations
|
|
|
|
import json
|
|
import sys
|
|
import time
|
|
|
|
import httpx
|
|
import paramiko
|
|
|
|
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
|
|
|
|
PASS = "4669805"
|
|
TENCENT = "82.157.112.245"
|
|
OVERSEAS = "107.173.30.245"
|
|
|
|
REMOTE = r'''
|
|
import json, os, subprocess, socket
|
|
print("=== env ===")
|
|
out=subprocess.check_output(["systemctl","show","douyinweb-api","-p","Environment","--value"], text=True, errors="replace")
|
|
for p in out.split():
|
|
if "NEKO" in p or "NAT" in p:
|
|
print(p)
|
|
|
|
print("\n=== containers 5/6 ===")
|
|
for i in (5,6):
|
|
name=f"neko-{i}"
|
|
r=subprocess.run(["docker","inspect","-f",
|
|
"{{.State.Status}} {{.State.Running}} http={{index .NetworkSettings.Ports \"9200/tcp\"}} mux={{(index .Config.Env)}}",
|
|
name], capture_output=True, text=True)
|
|
# simpler inspect
|
|
r2=subprocess.run(["docker","inspect",name], capture_output=True, text=True)
|
|
if r2.returncode!=0:
|
|
print(i, "MISSING", r2.stderr[:200]); continue
|
|
j=json.loads(r2.stdout)[0]
|
|
env={e.split("=",1)[0]:e.split("=",1)[1] for e in j["Config"]["Env"] if "=" in e}
|
|
ports=j["NetworkSettings"]["Ports"] or {}
|
|
print(json.dumps({
|
|
"id": i,
|
|
"status": j["State"]["Status"],
|
|
"running": j["State"]["Running"],
|
|
"NAT1TO1": env.get("NEKO_WEBRTC_NAT1TO1"),
|
|
"ICELITE": env.get("NEKO_WEBRTC_ICELITE"),
|
|
"EPR": env.get("NEKO_WEBRTC_EPR"),
|
|
"ports": {k:v for k,v in ports.items() if v},
|
|
}, ensure_ascii=False))
|
|
|
|
print("\n=== host listen mux 52304/52305 ===")
|
|
for port in (52304,52305,9204,9205):
|
|
s=socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
|
s.settimeout(0.3)
|
|
try:
|
|
r=s.connect_ex(("127.0.0.1", port))
|
|
print(f"tcp {port}", "open" if r==0 else f"closed({r})")
|
|
finally:
|
|
s.close()
|
|
|
|
print("\n=== ufw / iptables sample ===")
|
|
subprocess.run(["bash","-lc","ufw status | head -5; iptables -t nat -L -n 2>/dev/null | grep -E '5230|525|PREROUTING' | head -40"], check=False)
|
|
|
|
print("\n=== compose ports for 5/6 ===")
|
|
from pathlib import Path
|
|
p=Path("/opt/douyinWEB/backend/data/neko/docker-compose.yml")
|
|
if p.exists():
|
|
text=p.read_text(encoding="utf-8", errors="replace")
|
|
# print neko-5 / neko-6 blocks roughly
|
|
for key in ("neko-5:", "neko-6:"):
|
|
idx=text.find(key)
|
|
print("---", key, "---")
|
|
print(text[idx:idx+900] if idx>=0 else "not found")
|
|
'''
|
|
|
|
|
|
def ssh_guest():
|
|
c = paramiko.SSHClient()
|
|
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
|
for i in range(8):
|
|
try:
|
|
c.connect(
|
|
OVERSEAS,
|
|
4014,
|
|
"eric",
|
|
PASS,
|
|
timeout=60,
|
|
banner_timeout=120,
|
|
allow_agent=False,
|
|
look_for_keys=False,
|
|
)
|
|
return c
|
|
except Exception as ex:
|
|
print("ssh", i, type(ex).__name__, flush=True)
|
|
time.sleep(2 + i)
|
|
raise SystemExit("ssh failed")
|
|
|
|
|
|
def run(c, cmd, timeout=120):
|
|
_, o, e = c.exec_command(cmd, timeout=timeout)
|
|
return (o.read() + e.read()).decode("utf-8", "replace")
|
|
|
|
|
|
def main():
|
|
print("=== HTTP edge probes ===", flush=True)
|
|
for url in (
|
|
"https://dy.nomadro.com/neko/5/",
|
|
"https://dy.nomadro.com/neko/6/",
|
|
"https://dy.nomadro.cn/neko/5/",
|
|
"https://dy.nomadro.cn/neko/6/",
|
|
):
|
|
try:
|
|
r = httpx.get(url, timeout=20, follow_redirects=True)
|
|
print(url, r.status_code, "len", len(r.content), "ct", r.headers.get("content-type"), flush=True)
|
|
except Exception as ex:
|
|
print(url, type(ex).__name__, ex, flush=True)
|
|
|
|
# UDP probe to public mux ports (best-effort: TCP connect also for mux)
|
|
print("\n=== public mux TCP probes ===", flush=True)
|
|
for host, ports in (
|
|
(TENCENT, (52304, 52305)),
|
|
(OVERSEAS, (52304, 52305)),
|
|
):
|
|
for port in ports:
|
|
try:
|
|
with socket_connect(host, port, 3) as ok:
|
|
print(f"{host}:{port}", ok)
|
|
except Exception as ex:
|
|
print(f"{host}:{port}", type(ex).__name__, ex)
|
|
|
|
g = ssh_guest()
|
|
sftp = g.open_sftp()
|
|
with sftp.file("/tmp/_neko56_diag.py", "w") as f:
|
|
f.write(REMOTE)
|
|
sftp.close()
|
|
print("\n=== guest diag ===", flush=True)
|
|
print(run(g, f"echo '{PASS}' | sudo -S -p '' python3 /tmp/_neko56_diag.py", timeout=90), flush=True)
|
|
|
|
# check DNAT on edges
|
|
print("=== overseas root DNAT ===", flush=True)
|
|
root = paramiko.SSHClient()
|
|
root.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
|
root.connect(OVERSEAS, 22, "root", "Xiao4669805", timeout=40, allow_agent=False, look_for_keys=False)
|
|
print(
|
|
run(
|
|
root,
|
|
"iptables -t nat -L PREROUTING -n -v | grep -E '5230[4-5]|525' | head -30; "
|
|
"iptables -t nat -L PREROUTING -n | grep -c 5230 || true",
|
|
timeout=30,
|
|
),
|
|
flush=True,
|
|
)
|
|
root.close()
|
|
|
|
print("=== tencent DNAT ===", flush=True)
|
|
cn = paramiko.SSHClient()
|
|
cn.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
|
cn.connect(TENCENT, 22, "ubuntu", "Xiao4669805", timeout=40, allow_agent=False, look_for_keys=False)
|
|
print(
|
|
run(
|
|
cn,
|
|
"echo Xiao4669805 | sudo -S -p '' bash -lc "
|
|
"'iptables -t nat -L PREROUTING -n -v | grep -E \"5230[4-5]|525\" | head -40; "
|
|
"iptables -t nat -L PREROUTING -n | grep -c 52304 || true; "
|
|
"ss -ulnp | grep -E \"52304|52305\" | head || true'",
|
|
timeout=40,
|
|
),
|
|
flush=True,
|
|
)
|
|
cn.close()
|
|
g.close()
|
|
|
|
|
|
def socket_connect(host, port, timeout):
|
|
import socket
|
|
|
|
class Ctx:
|
|
def __enter__(self):
|
|
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
|
s.settimeout(timeout)
|
|
try:
|
|
s.connect((host, port))
|
|
self.msg = "tcp_open"
|
|
except Exception as ex:
|
|
self.msg = f"tcp_fail:{type(ex).__name__}"
|
|
finally:
|
|
s.close()
|
|
return self.msg
|
|
|
|
def __exit__(self, *a):
|
|
return False
|
|
|
|
return Ctx()
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|