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

59 lines
1.7 KiB
Python

#!/usr/bin/env python3
"""Short probes: real IP HTTPS + light SSH on dylive."""
from __future__ import annotations
import ssl
import sys
import time
import urllib.request
import paramiko
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
# HTTPS to real IP with SNI
ctx = ssl.create_default_context()
for path in ("/", "/youtube", "/api/health"):
url = f"https://107.173.30.245{path}"
req = urllib.request.Request(url, headers={"Host": "dylive.nomadro.com"})
try:
with urllib.request.urlopen(req, timeout=12, context=ctx) as r:
print("sni", path, r.status)
except Exception as e:
print("sni", path, type(e).__name__, str(e)[:160])
c = paramiko.SSHClient()
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
print("ssh connecting...", flush=True)
c.connect(
"107.173.30.245",
22,
"root",
"Xiao4669805",
timeout=30,
allow_agent=False,
look_for_keys=False,
banner_timeout=60,
)
print("ssh ok", flush=True)
for cmd in (
"uptime; free -m | head -2",
"systemctl is-active caddy douyinweb-api douyinweb-web",
"ss -lntp | grep -E ':443|:4015|:8014' | head -10",
"curl -sS -m 4 -o /dev/null -w 'w:%{http_code}\n' http://127.0.0.1:4015/youtube || echo wfail",
"curl -sS -m 4 -o /dev/null -w 'a:%{http_code}\n' http://127.0.0.1:8014/api/health || echo afail",
"docker ps --filter name=douyinweb-neko --format '{{.Names}} {{.Status}}' | sort",
):
print(f"\n$ {cmd}", flush=True)
_i, o, e = c.exec_command(cmd, timeout=25)
o.channel.settimeout(25)
try:
out = (o.read() + e.read()).decode("utf-8", "replace")
except Exception as ex:
out = f"TIMEOUT {ex}"
print(out, flush=True)
c.close()
print("DONE")