mirror of
https://github.com/hotyue/IP-Sentinel.git
synced 2026-09-04 23:18:17 +08:00
fix(daemon): 同步锁定网络协议防重复发报,重构 Python Webhook 支持双栈及纯 IPv6 监听
This commit is contained in:
+16
-3
@@ -24,8 +24,15 @@ if pgrep -f "webhook.py $AGENT_PORT" > /dev/null; then
|
|||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# 1. 获取本机原生公网 IPv4 (强制去除所有不可见换行符和空格)
|
# 1. [v3.0.1修复] 严格按照 install.sh 锁定的网络协议 (v4/v6) 获取 IP
|
||||||
AGENT_IP=$(curl -4 -s -m 5 api.ip.sb/ip | tr -d '[:space:]')
|
RAW_IP=$(curl -${IP_PREF:-4} -s -m 5 api.ip.sb/ip | tr -d '[:space:]')
|
||||||
|
|
||||||
|
# 为新获取到的 v6 自动加方括号,以确保与之前锁定的格式对齐比对
|
||||||
|
if [[ "$RAW_IP" == *":"* ]] && [[ "$RAW_IP" != *"["* ]]; then
|
||||||
|
AGENT_IP="[${RAW_IP}]"
|
||||||
|
else
|
||||||
|
AGENT_IP="$RAW_IP"
|
||||||
|
fi
|
||||||
|
|
||||||
if [ -n "$AGENT_IP" ]; then
|
if [ -n "$AGENT_IP" ]; then
|
||||||
# --- [重点升级 2: 智能防打扰注册机制] ---
|
# --- [重点升级 2: 智能防打扰注册机制] ---
|
||||||
@@ -120,8 +127,14 @@ class AgentHandler(http.server.BaseHTTPRequestHandler):
|
|||||||
def log_message(self, format, *args):
|
def log_message(self, format, *args):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
import socket
|
||||||
|
# [v3.0.1修复] 自定义支持双栈/IPv6的 Server 类
|
||||||
|
class DualStackServer(socketserver.TCPServer):
|
||||||
|
address_family = socket.AF_INET6 if socket.has_ipv6 else socket.AF_INET
|
||||||
|
|
||||||
try:
|
try:
|
||||||
with socketserver.TCPServer(("", PORT), AgentHandler) as httpd:
|
bind_addr = "::" if socket.has_ipv6 else ""
|
||||||
|
with DualStackServer((bind_addr, PORT), AgentHandler) as httpd:
|
||||||
httpd.serve_forever()
|
httpd.serve_forever()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|||||||
Reference in New Issue
Block a user