Files
ykxmz/_build/find_cf_api_ip.sh
xmz7891 b62ac865ea ykxmz 1.5.0:修复手表端 TLS 证书校验 + MTU 修复网络稳定性
被控端
- 修复 MTU 问题:夹 MSS + 路径 MTU 探测(公网可用率 48% -> 100%)
- 复用 HTTP 连接(免掉每次新建 TLS 的 30% 握手失败)
- 每分钟回头找局域网,自动切回快 400 倍的路径
- 画面心跳帧:静止时省流量,客户端仍知道流是活的
- 锁屏时给出可操作的提示

手表端
- 内置 GTS Root R4 / GlobalSign Root CA,修 SSLHandshakeException
- 连接错误翻译成人话(证书/时间/解析/超时分别提示)
- 经中转连上后用服务器报的地址刷新已配对记录
- 新增局域网连接页面、服务器延迟检测

服务器端
- 支持 chunked 请求体(修每 16 秒一次的连接错乱与大面积 502)
- 网络调优脚本 net-tune.sh(开机自动应用)
- 管理页:批量删除、网络体检、下载区
- 隧道改 HTTP/2 + 双连接

文档
- 许可协议 / 安装前必读 / 安装后须知(作者:小麦子)
2026-10-06 19:01:05 +08:00

92 lines
3.1 KiB
Bash
Raw Permalink 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.
#!/bin/bash
# 查 api.cloudflare.com 到底该用哪个 IP。
#
# 现在钉的 104.16.132.229 返回的是 Cloudflare 错误页(error 1034),
# 说明这个 IP 不对 —— 我当初是随便挑的一个 Cloudflare 网段地址。
set -u
echo "===== 1. 当前响应内容到底是什么 ====="
curl -4 -s -D /tmp/h.txt -o /tmp/b.txt https://api.cloudflare.com/client/v4/user 2>/dev/null
echo " 响应头前几行:"
head -8 /tmp/h.txt | sed 's/^/ /'
echo
echo " 响应体前 300 字节:"
head -c 300 /tmp/b.txt | sed 's/^/ /'
echo
echo
echo "===== 2. 用公共 DNS 查真实 IP(绕开本地解析)====="
for dns in 1.1.1.1 8.8.8.8 223.5.5.5; do
echo " --- 经 $dns ---"
timeout 8 getent ahostsv4 api.cloudflare.com >/dev/null 2>&1
# 用 python 发 DNS 查询(设备上不一定有 dig/nslookup)
python3 - "$dns" <<'PY' 2>/dev/null || echo " (查不了)"
import socket, struct, sys
dns = sys.argv[1]
name = "api.cloudflare.com"
# 手搓一个 DNS A 查询
tid = 0x1234
flags = 0x0100
q = struct.pack(">HHHHHH", tid, flags, 1, 0, 0, 0)
for part in name.split("."):
q += bytes([len(part)]) + part.encode()
q += b"\x00" + struct.pack(">HH", 1, 1)
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.settimeout(5)
try:
s.sendto(q, (dns, 53))
data, _ = s.recvfrom(2048)
except Exception as exc:
print(f" 查询失败: {exc}")
raise SystemExit
# 跳过 header + question
idx = 12
while data[idx] != 0:
idx += data[idx] + 1
idx += 5
ancount = struct.unpack(">H", data[6:8])[0]
found = []
for _ in range(ancount):
if data[idx] & 0xC0:
idx += 2
else:
while data[idx] != 0:
idx += data[idx] + 1
idx += 1
rtype, _cls, _ttl, rdlen = struct.unpack(">HHIH", data[idx:idx+10])
idx += 10
if rtype == 1 and rdlen == 4:
found.append(".".join(str(b) for b in data[idx:idx+4]))
idx += rdlen
print(" " + (", ".join(found) if found else "没有 A 记录"))
PY
done
echo
echo "===== 3. 挨个试候选 IP,看哪个返回正常的 API JSON ====="
for ip in 104.16.132.229 104.16.133.229 104.17.0.1 104.18.0.1 172.64.0.1 162.159.0.1; do
OUT=$(timeout 12 curl -4 -s -w '\n%{http_code}' \
--resolve "api.cloudflare.com:443:$ip" \
https://api.cloudflare.com/client/v4/user 2>/dev/null)
CODE=$(echo "$OUT" | tail -1)
FIRST=$(echo "$OUT" | head -c 90 | tr -d '\n')
printf " %-16s HTTP %-4s %s\n" "$ip" "${CODE:-超时}" "$FIRST"
done
echo
echo "===== 4. 去掉 hosts 钉的 IP,用系统解析试试 ====="
# 临时备份并移除
cp /etc/hosts /tmp/hosts.bak
grep -v 'api.cloudflare.com' /etc/hosts > /tmp/hosts.new
cat /tmp/hosts.new > /etc/hosts
echo " 现在的解析: $(getent ahostsv4 api.cloudflare.com | head -1 | awk '{print $1}')"
OUT=$(timeout 12 curl -4 -s -w '\n%{http_code}' https://api.cloudflare.com/client/v4/user 2>/dev/null)
echo " HTTP $(echo "$OUT" | tail -1) $(echo "$OUT" | head -c 90)"
echo
echo " 把 hosts 恢复回去(钉 IP 还是需要的,不然全乱)"
cp /tmp/hosts.bak /etc/hosts
getent ahostsv4 api.cloudflare.com | head -1 | sed 's/^/ /'