167 lines
6.8 KiB
Python
167 lines
6.8 KiB
Python
#!/usr/bin/env python3
|
|
"""Re-analyze Neko path for VPS hub + physical ops-neko (CN WG preferred). Read-only."""
|
|
from __future__ import annotations
|
|
|
|
import json
|
|
import sys
|
|
import time
|
|
|
|
import httpx
|
|
import paramiko
|
|
|
|
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
|
|
|
|
|
|
def ssh(host, port, user, pw):
|
|
c = paramiko.SSHClient()
|
|
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
|
for i in range(6):
|
|
try:
|
|
c.connect(
|
|
host, port, user, pw,
|
|
timeout=45, banner_timeout=120,
|
|
allow_agent=False, look_for_keys=False,
|
|
)
|
|
return c
|
|
except Exception as ex:
|
|
print("retry", i, ex, flush=True)
|
|
time.sleep(3)
|
|
raise SystemExit("ssh fail")
|
|
|
|
|
|
def run(c, cmd, t=120):
|
|
_i, o, e = c.exec_command(cmd, timeout=t)
|
|
o.channel.recv_exit_status()
|
|
return (o.read() + e.read()).decode("utf-8", "replace")
|
|
|
|
|
|
print("===== PUBLIC CN vs COM neko/ops =====", flush=True)
|
|
with httpx.Client(follow_redirects=False, timeout=20) as cl:
|
|
for url in [
|
|
"https://dy.nomadro.cn/api/health",
|
|
"https://dy.nomadro.cn/neko/1/",
|
|
"https://dy.nomadro.cn/ops-neko/1/",
|
|
"https://dy.nomadro.com/neko/1/",
|
|
"https://dy.nomadro.com/ops-neko/1/",
|
|
"https://dylive.nomadro.com/neko/1/",
|
|
"https://dylive.nomadro.com/ops-neko/1/",
|
|
"https://dylive.nomadro.com/api/health",
|
|
]:
|
|
try:
|
|
r = cl.get(url)
|
|
print(f"{r.status_code} {url} loc={r.headers.get('location','')[:60]}", flush=True)
|
|
except Exception as ex:
|
|
print(f"ERR {url} {ex}", flush=True)
|
|
|
|
v = ssh("107.173.30.245", 22, "root", "Xiao4669805")
|
|
print("===== VPS (dylive hub) neko/ops perspective =====", flush=True)
|
|
print(run(v, r"""
|
|
set +e
|
|
echo '--- dylive local neko containers ---'
|
|
docker ps -a --format '{{.Names}} {{.Status}} {{.Ports}}' | grep -iE 'douyinweb-neko|ops-neko' | head -30
|
|
echo '--- who owns 9200-9207 on VPS ---'
|
|
ss -lntp | grep -E ':(920[0-7]|1820[0-7])\b' | head -20
|
|
echo '--- frp-aux still binding neko ports? ---'
|
|
systemctl is-active dy-frp-http-aux
|
|
# does dylive caddy have ops-neko?
|
|
grep -c 'ops-neko' /etc/caddy/sites/dylive.nomadro.com.caddy
|
|
grep -nE 'ops-neko|neko/1' /etc/caddy/sites/dylive.nomadro.com.caddy | head -15
|
|
echo '--- login + assign/ops sync status (need cookie) ---'
|
|
# try admin login
|
|
CS=$(mktemp)
|
|
curl -sS -m 15 -c "$CS" -b "$CS" -X POST http://127.0.0.1:8014/api/auth/login \
|
|
-H 'Content-Type: application/json' \
|
|
-d '{"username":"hackrobot","password":"Xiao4669805@"}' | head -c 200; echo
|
|
echo '--- host-profile ---'
|
|
curl -sS -m 10 -b "$CS" http://127.0.0.1:8014/api/ops/host-profile | head -c 600; echo
|
|
echo '--- yt assign groups neko fields ---'
|
|
curl -sS -m 15 -b "$CS" http://127.0.0.1:8014/api/youtube/assign/groups 2>/dev/null | python3 -c '
|
|
import sys,json
|
|
raw=sys.stdin.read()
|
|
try: d=json.loads(raw)
|
|
except Exception as e: print("parse fail",e,raw[:200]); raise SystemExit
|
|
rows=d if isinstance(d,list) else d.get("groups") or d.get("items") or d.get("data") or []
|
|
print("count", len(rows) if isinstance(rows,list) else type(rows))
|
|
if isinstance(rows, list):
|
|
for g in rows[:20]:
|
|
print({
|
|
"name": (g.get("name") or g.get("title") or "")[:40],
|
|
"neko_enabled": g.get("neko_enabled"),
|
|
"neko_instance_id": g.get("neko_instance_id"),
|
|
"desktop_target": g.get("desktop_target") or g.get("neko_desktop_target"),
|
|
"ops_bound": g.get("ops_neko_bound"),
|
|
"ops_slot": g.get("ops_neko_slot"),
|
|
"ops_url": (g.get("ops_neko_open_url") or "")[:80],
|
|
"neko_url": (g.get("neko_open_url") or g.get("open_url") or "")[:80],
|
|
})
|
|
'
|
|
echo '--- ops peer / remote catalog ---'
|
|
curl -sS -m 10 -b "$CS" http://127.0.0.1:8014/api/ops/neko/peer 2>/dev/null | head -c 500; echo
|
|
curl -sS -m 10 -b "$CS" http://127.0.0.1:8014/api/ops/neko/remote-catalog 2>/dev/null | head -c 800; echo
|
|
curl -sS -m 10 -b "$CS" http://127.0.0.1:8014/api/ops/neko/sync-status 2>/dev/null | head -c 500; echo
|
|
echo '--- neko status api ---'
|
|
curl -sS -m 10 -b "$CS" http://127.0.0.1:8014/api/youtube/neko/status 2>/dev/null | head -c 800; echo
|
|
rm -f "$CS"
|
|
"""), flush=True)
|
|
v.close()
|
|
|
|
p = ssh("107.173.30.245", 4014, "eric", "4669805")
|
|
print("===== PHYSICAL (ops-neko edge) =====", flush=True)
|
|
print(run(p, r"""
|
|
echo '4669805' | sudo -S -p '' bash -lc '
|
|
set +e
|
|
CS=$(mktemp)
|
|
curl -sS -m 15 --noproxy "*" -c "$CS" -b "$CS" -X POST http://127.0.0.1:8014/api/auth/login \
|
|
-H "Content-Type: application/json" \
|
|
-d "{\"username\":\"hackrobot\",\"password\":\"Xiao4669805@\"}" | head -c 200; echo
|
|
echo "--- host-profile ---"
|
|
curl -sS -m 10 --noproxy "*" -b "$CS" http://127.0.0.1:8014/api/ops/host-profile | head -c 700; echo
|
|
echo "--- peer / sync ---"
|
|
curl -sS -m 10 --noproxy "*" -b "$CS" http://127.0.0.1:8014/api/ops/neko/peer | head -c 600; echo
|
|
curl -sS -m 10 --noproxy "*" -b "$CS" http://127.0.0.1:8014/api/ops/neko/sync-status | head -c 600; echo
|
|
echo "--- ops instances ---"
|
|
curl -sS -m 10 --noproxy "*" -b "$CS" http://127.0.0.1:8014/api/ops/neko/instances 2>/dev/null | python3 -c "
|
|
import sys,json
|
|
raw=sys.stdin.read()
|
|
try: d=json.loads(raw)
|
|
except Exception as e: print(raw[:300]); raise SystemExit
|
|
rows=d if isinstance(d,list) else d.get(\"instances\") or d.get(\"items\") or []
|
|
print(\"count\", len(rows))
|
|
for r in rows[:15]:
|
|
print({k:r.get(k) for k in (\"slot\",\"name\",\"want_running\",\"running\",\"open_url\",\"bind_remote_group_id\",\"public_url\") if k in r or True})
|
|
print(\" open\", (r.get(\"open_url\") or r.get(\"public_url\") or \"\")[:100])
|
|
"
|
|
echo "--- nat1to1 on running ops/neko ---"
|
|
for c in douyinweb-ops-neko-1 douyinweb-neko-1; do
|
|
echo "== $c =="
|
|
docker inspect "$c" --format "{{json .Config.Env}}" 2>/dev/null | tr "," "\n" | grep -E "NAT1TO1|BITRATE|MAX_FPS|DESKTOP_SCREEN|ICELITE|UDPMUX|EPR|BROWSER_PROXY|START_URL" || echo missing
|
|
done
|
|
echo "--- wg-dy-cn vs wg-dy ---"
|
|
wg show wg-dy-cn latest-handshakes
|
|
wg show wg-dy latest-handshakes
|
|
ping -c 2 -W 2 10.9.0.1 | tail -3
|
|
ping -c 2 -W 2 10.8.0.1 | tail -3
|
|
# can CN edge reach phys neko via 10.9.0.2?
|
|
curl -sS -m 5 --noproxy "*" -o /dev/null -w "local_ops1=%{http_code}\n" http://127.0.0.1:18200/
|
|
curl -sS -m 5 --noproxy "*" -o /dev/null -w "local_neko1=%{http_code}\n" http://127.0.0.1:9200/
|
|
echo "--- preferred base / settings ---"
|
|
curl -sS -m 10 --noproxy "*" -b "$CS" http://127.0.0.1:8014/api/settings 2>/dev/null | python3 -c "
|
|
import sys,json
|
|
raw=sys.stdin.read()
|
|
try: d=json.loads(raw)
|
|
except Exception: print(raw[:200]); raise SystemExit
|
|
if isinstance(d, dict):
|
|
for k in sorted(d):
|
|
if any(x in k.lower() for x in (\"neko\",\"nat\",\"ops\",\"public\",\"domain\")):
|
|
v=d[k]
|
|
if isinstance(v,str) and len(v)>120: v=v[:120]
|
|
print(k, \"=\", v)
|
|
" 2>/dev/null | head -60
|
|
rm -f "$CS"
|
|
echo "--- mem ---"
|
|
free -h | head -3
|
|
'
|
|
"""), flush=True)
|
|
p.close()
|
|
print("DONE", flush=True)
|