#!/bin/bash # 检查隧道现在通不通(从设备自己这边看)。 set -u URL=$(cat /root/lanremote-relay/public_url.txt 2>/dev/null || echo "") echo " 隧道地址: ${URL:-(没有)}" echo echo " 1. tunnel 服务: $(systemctl is-active lanremote-tunnel)" echo " 2. 已注册的连接数: $(grep -c 'Registered tunnel connection' /root/lanremote-relay/tunnel.log 2>/dev/null || echo 0)" echo echo " 3. 从设备访问自己的公网地址:" if [ -n "$URL" ]; then for i in 1 2 3 4 5; do C=$(timeout 15 curl -s -o /dev/null -w '%{http_code}' "$URL/v1/health" 2>/dev/null) printf " 第 %d 次: HTTP %s\n" "$i" "${C:-超时}" [ "$C" = "200" ] && break sleep 5 done else echo " 没有地址" fi echo echo " 4. 隧道日志尾部:" tail -6 /root/lanremote-relay/tunnel.log 2>/dev/null | sed 's/^/ /' echo echo " 5. 有没有再报 context deadline exceeded:" grep -c 'context deadline exceeded' /root/lanremote-relay/tunnel.log 2>/dev/null || echo 0