Files
ykxmz/_build/find_cf_api_ip.sh
T
xmz7891 b705216e4a ykxmz 1.5.0锛氫慨澶嶆墜琛ㄧ TLS 璇佷功鏍¢獙 + MTU 淇缃戠粶绋冲畾鎬?
琚帶绔?- 淇 MTU 闂锛氬す MSS + 璺緞 MTU 鎺㈡祴锛堝叕缃戝彲鐢ㄧ巼 48% -> 100%锛?- 澶嶇敤 HTTP 杩炴帴锛堝厤鎺夋瘡娆℃柊寤?TLS 鐨?30% 鎻℃墜澶辫触锛?- 姣忓垎閽熷洖澶存壘灞€鍩熺綉锛岃嚜鍔ㄥ垏鍥炲揩 400 鍊嶇殑璺緞
- 鐢婚潰蹇冭烦甯э細闈欐鏃剁渷娴侀噺锛屽鎴风浠嶇煡閬撴祦鏄椿鐨?- 閿佸睆鏃剁粰鍑哄彲鎿嶄綔鐨勬彁绀?
鎵嬭〃绔?- 鍐呯疆 GTS Root R4 / GlobalSign Root CA锛屼慨 SSLHandshakeException
- 杩炴帴閿欒缈昏瘧鎴愪汉璇濓紙璇佷功/鏃堕棿/瑙f瀽/瓒呮椂鍒嗗埆鎻愮ず锛?- 缁忎腑杞繛涓婂悗鐢ㄦ湇鍔″櫒鎶ョ殑鍦板潃鍒锋柊宸查厤瀵硅褰?- 鏂板灞€鍩熺綉杩炴帴椤甸潰銆佹湇鍔″櫒寤惰繜妫€娴?
鏈嶅姟鍣ㄧ
- 鏀寔 chunked 璇锋眰浣擄紙淇瘡 16 绉掍竴娆$殑杩炴帴閿欎贡涓庡ぇ闈㈢Н 502锛?- 缃戠粶璋冧紭鑴氭湰 net-tune.sh锛堝紑鏈鸿嚜鍔ㄥ簲鐢級
- 绠$悊椤碉細鎵归噺鍒犻櫎銆佺綉缁滀綋妫€銆佷笅杞藉尯
- 闅ч亾鏀?HTTP/2 + 鍙岃繛鎺?
鏂囨。
- 璁稿彲鍗忚 / 瀹夎鍓嶅繀璇?/ 瀹夎鍚庨』鐭ワ紙浣滆€咃細灏忛害瀛愶級
2026-10-06 19:01:05 +08:00

92 lines
3.1 KiB
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.
#!/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/^/ /'