Files
ShellCrash/scripts/libs/get_ecsip.sh
Feng Yu c4532c979f fix(ecs): 公网IP轮询加IPv4校验,新增oray源,避免错误页伪成功
原轮询 [ -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 解析失败)
2026-07-11 22:42:53 +08:00

17 lines
701 B
Bash
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
get_ecs_address() {
for f in /tmp/resolv.conf.auto /tmp/resolv.conf /tmp/resolv.conf.d/resolv.conf.auto; do
[ -f "$f" ] || continue
ip=$(grep -A1 "^# Interface wan$" "$f" | grep nameserver | awk '{printf "%s ", $2}')
[ -n "$ip" ] && return
done
. "$CRASHDIR"/libs/web_get_lite.sh
#轮询公网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
}
get_ecs_address
[ -n "$ip" ] && ecs_address="${ip%.*}.0/24"