91 lines
2.6 KiB
Python
91 lines
2.6 KiB
Python
#!/usr/bin/env python3
|
|
"""Debug one-way WG: guest->VPS works, VPS->guest fails. Live."""
|
|
from __future__ import annotations
|
|
|
|
import sys
|
|
import time
|
|
|
|
import httpx
|
|
import paramiko
|
|
|
|
sys.stdout.reconfigure(encoding="utf-8", errors="replace", line_buffering=True)
|
|
|
|
|
|
def connect(port=22, user="root", pw="Xiao4669805"):
|
|
c = paramiko.SSHClient()
|
|
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
|
c.connect(
|
|
"107.173.30.245",
|
|
port,
|
|
user,
|
|
pw,
|
|
timeout=25,
|
|
banner_timeout=40,
|
|
allow_agent=False,
|
|
look_for_keys=False,
|
|
)
|
|
print(f"connected :{port}", flush=True)
|
|
return c
|
|
|
|
|
|
def run(c, cmd, t=60):
|
|
print(f"$ {cmd[:220]}", flush=True)
|
|
_i, o, e = c.exec_command(cmd, timeout=t)
|
|
while not o.channel.exit_status_ready():
|
|
if o.channel.recv_ready():
|
|
sys.stdout.write(o.channel.recv(4096).decode("utf-8", "replace"))
|
|
sys.stdout.flush()
|
|
if o.channel.recv_stderr_ready():
|
|
sys.stdout.write(o.channel.recv_stderr(4096).decode("utf-8", "replace"))
|
|
sys.stdout.flush()
|
|
time.sleep(0.1)
|
|
sys.stdout.write((o.read() + e.read()).decode("utf-8", "replace"))
|
|
sys.stdout.flush()
|
|
print("->", o.channel.recv_exit_status(), flush=True)
|
|
|
|
|
|
print("## VPS conf + keepalive + tcpdump sample", flush=True)
|
|
v = connect(22)
|
|
run(v, "cat /etc/wireguard/wg-dy.conf; echo ---; sysctl net.ipv4.conf.all.rp_filter net.ipv4.conf.wg-dy.rp_filter 2>/dev/null; iptables -L OUTPUT -n | head -15")
|
|
run(
|
|
v,
|
|
# force keepalive on server peer + dump a few packets
|
|
"wg set wg-dy peer 63+cGgkjfB3XtHZgv/fwY7czeBBMBN94EiOvK8747yA= persistent-keepalive 15; "
|
|
"timeout 8 tcpdump -ni any udp port 51820 -c 12 -tttt 2>&1 | tail -30 || true; "
|
|
"wg show wg-dy",
|
|
t=40,
|
|
)
|
|
v.close()
|
|
|
|
print("## guest conf + ping", flush=True)
|
|
g = connect(4014, "eric", "4669805")
|
|
run(
|
|
g,
|
|
"echo 4669805 | sudo -S -p '' bash -lc '"
|
|
"cat /etc/wireguard/wg-dy.conf; echo ---; "
|
|
"wg show wg-dy; "
|
|
"ping -c 5 -W 2 10.8.0.1 | tail -8"
|
|
"'",
|
|
t=40,
|
|
)
|
|
g.close()
|
|
|
|
print("## recheck tunnel", flush=True)
|
|
time.sleep(3)
|
|
v = connect(22)
|
|
run(
|
|
v,
|
|
"wg show wg-dy; ping -c 3 -W 2 10.8.0.2 | tail -5; "
|
|
"curl -sS -m 8 -o /dev/null -w via_wg=%{http_code}\\\\n http://10.8.0.2:8014/api/health",
|
|
t=30,
|
|
)
|
|
v.close()
|
|
|
|
with httpx.Client(follow_redirects=False, timeout=12) as cl:
|
|
for u in ["https://dy.nomadro.com/api/health", "https://dylive.nomadro.com/api/health"]:
|
|
try:
|
|
print(u, "->", cl.get(u).status_code, flush=True)
|
|
except Exception as ex:
|
|
print(u, ex, flush=True)
|
|
print("DONE", flush=True)
|