#!/bin/bash # 检查隧道/中转当前状态(之前的 A/B 脚本可能留了坏配置) set -u URL=https://relay.xxmxxs.top RELAY_DIR=/root/lanremote-relay echo "===== 服务 =====" for s in lanremote-tunnel lanremote-tunnel-quic lanremote-relay \ lanremote-watchdog.timer; do printf " %-28s %-10s %s\n" "$s" \ "$(systemctl is-active "$s" 2>/dev/null)" \ "$(systemctl is-enabled "$s" 2>/dev/null)" done echo echo "===== unit 的 ExecStart =====" grep ExecStart /etc/systemd/system/lanremote-tunnel.service 2>/dev/null \ | sed 's/^/ /' echo echo "===== cloudflared 进程(应有 1 个,参数顺序要正确)=====" pgrep -a -f cloudflared | sed 's/^/ /' || echo " 没有进程" echo echo "===== 隧道连接数 + 协议 =====" echo -n " ha_connections = " curl -s --max-time 5 http://127.0.0.1:20241/metrics 2>/dev/null \ | grep '^cloudflared_tunnel_ha_connections' | awk '{print $2}' echo " 协议: $(grep -o 'protocol=[a-z0-9]*' "$RELAY_DIR/tunnel.log" 2>/dev/null | tail -1)" echo echo "===== 本地源站 =====" echo " HTTP $(timeout 8 curl -s -o /dev/null -w '%{http_code}' \ http://127.0.0.1:8080/v1/health 2>/dev/null)" echo " body: $(timeout 8 curl -s http://127.0.0.1:8080/v1/health 2>/dev/null | head -c 120)" echo echo "===== 公网(打 8 次)=====" ok=0 for i in $(seq 1 8); do c=$(timeout 15 curl -4 -s -o /dev/null -w '%{http_code}' \ -H 'User-Agent: LanRemote/1.4.0' "$URL/v1/health" 2>/dev/null) printf " %s" "${c:-000}" [ "$c" = "200" ] && ok=$((ok+1)) sleep 2 done echo echo " 公网 $ok/8" echo echo "===== 公网 POST 登记(这才是被控端走的路径)=====" BODY='{"deviceId":"diag-1","code":"481111","name":"诊断","version":"1.4.0"}' echo " 响应: $(timeout 20 curl -4 -s -H 'User-Agent: LanRemote/1.4.0' \ -H 'Content-Type: application/json' -d "$BODY" \ "$URL/v1/agent/register" 2>&1 | head -c 200)" echo echo "===== 隧道日志尾部 =====" tail -8 "$RELAY_DIR/tunnel.log" 2>/dev/null | sed 's/^/ /'