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

44 lines
2.2 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')
print('=== fix iptables: 51821 BEFORE baota firewall ===')
print(run(d, r"""sudo bash -c '
# Remove duplicate accepts
iptables -D INPUT -p udp --dport 51821 -j ACCEPT 2>/dev/null || true
iptables -D YJ-FIREWALL-INPUT -p udp --dport 51821 -j ACCEPT 2>/dev/null || true
# Insert at very top of INPUT
iptables -I INPUT 1 -p udp --dport 51821 -j ACCEPT
iptables -I YJ-FIREWALL-INPUT 1 -p udp --dport 51821 -j ACCEPT
iptables -L INPUT -n -v --line-numbers | head -8
iptables -L YJ-FIREWALL-INPUT -n -v --line-numbers | head -8
ip -4 addr show eth0
curl -sS -m 3 http://metadata.tencentyun.com/latest/meta-data/public-ipv4; echo
'""",30))
# capture on all ifaces
d.exec_command('sudo timeout 15 tcpdump -ni any udp port 51821 -c 5 >/tmp/cap-any.log 2>&1 &',timeout=3)
time.sleep(1)
v=ssh('107.173.30.245',22,'root','Xiao4669805')
g=ssh('107.173.30.245',4014,'eric','4669805')
print('VPS send:', run(v,'wg-quick down wg-dy-cn; wg-quick up wg-dy-cn; echo probe | nc -u -w2 82.157.112.245 51821; sleep 1; wg show wg-dy-cn',25))
print('PVE send:', 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(10)
print('\n=== tcpdump any ===')
print(run(d,'cat /tmp/cap-any.log',10))
print('\n=== domestic wg ===')
print(run(d,'sudo wg show wg-dy-cn',10))
if '1 packet' in run(d,'cat /tmp/cap-any.log',5) or 'handshake' in run(d,'sudo wg show wg-dy-cn',10):
print('PACKETS OK')
v=ssh('107.173.30.245',22,'root','Xiao4669805')
print('\n=== ping after fix ===')
print(run(v,'ping -c 3 -W 3 10.9.0.2 | tail -3; curl -sS -m 8 -o /dev/null -w "api=%{http_code} t=%{time_total}s\n" http://10.9.0.2:8014/api/health',25))
d.close(); v.close(); g.close()