douyinWEB/scripts/_diag_wg_cn_now.py
eric d409e416da Ship physical dual-edge stack, Studio CDP live metrics, and ops tooling.
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>
2026-09-04 22:42:40 -05:00

29 lines
1.4 KiB
Python

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import sys, time
import paramiko
sys.stdout.reconfigure(encoding='utf-8', errors='replace')
def ssh(h,p,u,pw):
c=paramiko.SSHClient(); c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
c.connect(h,p,u,pw,timeout=45,allow_agent=False,look_for_keys=False); return c
def run(c,cmd,t=60):
_,o,e=c.exec_command(cmd,timeout=t); return (o.read()+e.read()).decode('utf-8','replace')
print('=== restart all wg-dy-cn ===')
d=ssh('82.157.112.245',22,'ubuntu','Xiao4669805')
print(run(d,'sudo wg-quick down wg-dy-cn 2>/dev/null; sudo wg-quick up wg-dy-cn; sudo wg show wg-dy-cn',30))
v=ssh('107.173.30.245',22,'root','Xiao4669805')
print(run(v,'wg-quick down wg-dy-cn 2>/dev/null; wg-quick up wg-dy-cn; sleep 3; wg show wg-dy-cn',30))
g=ssh('107.173.30.245',4014,'eric','4669805')
print(run(g,"echo '4669805' | sudo -S wg-quick down wg-dy-cn 2>/dev/null; echo '4669805' | sudo -S wg-quick up wg-dy-cn; sleep 3; echo '4669805' | sudo -S wg show wg-dy-cn",45))
time.sleep(3)
print('\n=== domestic after restarts ===')
print(run(d,'sudo wg show wg-dy-cn',15))
print('\n=== VPS ping/curl ===')
print(run(v,'ping -c 4 -W 3 10.9.0.2; curl -sS -m 10 -o /dev/null -w "api_cn=%{http_code} t=%{time_total}s\n" http://10.9.0.2:8014/api/health; ping -c 4 -W 3 10.8.0.2 | tail -2',45))
print('\n=== physical ping hub ===')
print(run(g,"echo '4669805' | sudo -S ping -c 4 -W 3 10.9.0.1 | tail -3",20))
d.close(); v.close(); g.close()