From f7f790e691aea28cdc0cd8ffa85c147f70044c79 Mon Sep 17 00:00:00 2001 From: Feng Yu Date: Sun, 5 Jul 2026 21:31:44 +0800 Subject: [PATCH 1/2] =?UTF-8?q?fix(ecs):=20singbox=20=E5=88=86=E6=94=AF?= =?UTF-8?q?=E8=A1=A5=E9=BD=90=20ecs=5Faddress=20=E5=88=A4=E7=A9=BA,?= =?UTF-8?q?=E5=A4=B1=E8=B4=A5=E6=97=B6=E7=BB=88=E7=AB=AF=E5=91=8A=E8=AD=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit singbox_modify.sh 之前 ecs_address 为空时仍写入 client_subnet:"", 导致 sing-box 启动时 netip.ParsePrefix("") 报 'no /' FATAL, 服务无法启动。根因是 get_ecsip.sh 在部分环境(如梅林 resolv.conf 无 # Interface wan 标记、members.3322.org 被限流)下拿不到公网 IP。 - singbox_modify.sh: 与 mihomo 分支对齐,加 [ -n ecs_address ] 判空, 失败时不写字段并 logger 告警 - clash_modify.sh: logger 补颜色码 33(黄色),使告警同样打印到终端, 原来无颜色码只写日志文件用户无感知 --- scripts/starts/clash_modify.sh | 2 +- scripts/starts/singbox_modify.sh | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/scripts/starts/clash_modify.sh b/scripts/starts/clash_modify.sh index 8e539fa7e..0424b35e8 100644 --- a/scripts/starts/clash_modify.sh +++ b/scripts/starts/clash_modify.sh @@ -21,7 +21,7 @@ prepare_clash_base_config() { if [ -n "$ecs_address" ];then dns_fallback=$(echo "$dns_fallback, " | sed "s|, |#ecs-override=true\&ecs=$ecs_address, |g" | sed 's|, $||') else - logger "自动获取ecs网段失败!" + logger "自动获取ecs网段失败!" 33 fi } } diff --git a/scripts/starts/singbox_modify.sh b/scripts/starts/singbox_modify.sh index 3a9180cdb..b3d448515 100644 --- a/scripts/starts/singbox_modify.sh +++ b/scripts/starts/singbox_modify.sh @@ -112,7 +112,11 @@ prepare_dns_config() { #ecs优化 [ "$ecs_subnet" = ON ] && { . "$CRASHDIR"/libs/get_ecsip.sh - client_subnet='"client_subnet": "'"$ecs_address"'",' + if [ -n "$ecs_address" ]; then + client_subnet='"client_subnet": "'"$ecs_address"'",' + else + logger "自动获取ecs网段失败!" 33 + fi } #根据dns模式生成 [ "$dns_mod" = "redir_host" ] && { From 7b04b5a6b12099a4b16265621e876fc8f7df220e Mon Sep 17 00:00:00 2001 From: Feng Yu Date: Sun, 5 Jul 2026 22:10:52 +0800 Subject: [PATCH 2/2] =?UTF-8?q?fix(ecs):=20=E5=85=AC=E7=BD=91IP=E8=BD=AE?= =?UTF-8?q?=E8=AF=A2=E5=8A=A0IPv4=E6=A0=A1=E9=AA=8C,=E6=96=B0=E5=A2=9Eoray?= =?UTF-8?q?=E6=BA=90,=E9=81=BF=E5=85=8D=E9=94=99=E8=AF=AF=E9=A1=B5?= =?UTF-8?q?=E4=BC=AA=E6=88=90=E5=8A=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 原轮询 [ -n "$ip" ] 只判非空,members.3322.org 被限流返回 429 HTML 错误页时也判为成功 return,后续更可靠的源不会被尝试。 - 每个响应用 grep -oE 提取合法 IPv4,提取失败(HTML/空)则继续下一个 - 新增 http://ddns.oray.com/checkip 放首位(响应含 'Current IP Address:' 前缀,grep 提取末尾 IPv4),比 3322 免费 DDNS 更稳定 - 移除 http://4.ipw.cn(部分运营商 DNS 解析失败) --- scripts/libs/get_ecsip.sh | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/scripts/libs/get_ecsip.sh b/scripts/libs/get_ecsip.sh index fa0b68a52..ba8e10a20 100644 --- a/scripts/libs/get_ecsip.sh +++ b/scripts/libs/get_ecsip.sh @@ -6,8 +6,9 @@ get_ecs_address() { [ -n "$ip" ] && return done . "$CRASHDIR"/libs/web_get_lite.sh - for web in http://members.3322.org/dyndns/getip http://4.ipw.cn http://ipinfo.io/ip; do - ip=$(web_get_lite "$web" 0) + #轮询公网IP,提取并校验为合法IPv4才采用,否则继续尝试下一个 + for web in http://ddns.oray.com/checkip http://members.3322.org/dyndns/getip http://ipinfo.io/ip; do + ip=$(web_get_lite "$web" 0 | grep -oE '([0-9]{1,3}\.){3}[0-9]{1,3}' | tail -1) [ -n "$ip" ] && return done }