douyinWEB/scripts/_diag_wg_cn_packets.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

35 lines
1.8 KiB
Python

#!/usr/bin/env python3
import paramiko, sys, time
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')
d=ssh('82.157.112.245',22,'ubuntu','Xiao4669805')
# capture + send from both sides
d.exec_command('sudo timeout 12 tcpdump -ni eth0 udp port 51821 -vv >/tmp/cap51821.log 2>&1 &',timeout=3)
time.sleep(1)
v=ssh('107.173.30.245',22,'root','Xiao4669805')
print('VPS public IP:', run(v,'curl -sS -m 3 https://api.ipify.org; echo',10).strip())
print('VPS wg restart:', run(v,'wg-quick down wg-dy-cn; wg-quick up wg-dy-cn; sleep 2; wg show wg-dy-cn',20))
g=ssh('107.173.30.245',4014,'eric','4669805')
print('PVE public IP:', run(g,"curl -sS -m 3 https://api.ipify.org 2>&1 || curl -sS -m 3 http://ip.sb 2>&1; echo",15).strip())
print('PVE wg restart:', run(g,"echo '4669805' | sudo -S wg-quick down wg-dy-cn; echo '4669805' | sudo -S wg-quick up wg-dy-cn; sleep 2; echo '4669805' | sudo -S wg show wg-dy-cn",30))
time.sleep(8)
print('\n=== tcpdump eth0:51821 ===')
print(run(d,'cat /tmp/cap51821.log',10))
print('\n=== domestic wg ===')
print(run(d,'sudo wg show wg-dy-cn',10))
print('\n=== domestic iptables INPUT top ===')
print(run(d,'sudo iptables -L INPUT -n -v | head -12',10))
print('\n=== test nc from VPS ===')
d.exec_command('sudo timeout 8 tcpdump -ni eth0 host 107.173.30.245 and udp port 51821 -c 3 >/tmp/cap2.log 2>&1 &',timeout=3)
time.sleep(1)
print(run(v,'for i in 1 2 3; do echo hello | nc -u -w1 82.157.112.245 51821; done',15))
time.sleep(3)
print(run(d,'cat /tmp/cap2.log',10))
d.close(); v.close(); g.close()