Files
ykxmz/_tests/test_cf_useragent.py
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

73 lines
2.5 KiB
Python
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.
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""测 Cloudflare 放行哪些 User-Agent。
背景:固定域名上线后,/v1/health 用 PowerShell 访问是 200,
但 Python urllib(默认 UA = Python-urllib/3.11)拿到 403 + error code 1010。
1010 = Cloudflare 的 Browser Integrity Check 判定为可疑客户端。
被控端(Python)和手表(Java)都会因此连不上 —— 必须换一个能过的 UA。
"""
import urllib.error
import urllib.request
URL = "https://relay.xxmxxs.top/v1/health"
AGENTS = [
("Python 默认(现在用的)", None),
("LanRemote/1.4.0", "LanRemote/1.4.0"),
("curl/8.0", "curl/8.0.1"),
("Mozilla/5.0 (Windows NT 10.0; Win64; x64)",
"Mozilla/5.0 (Windows NT 10.0; Win64; x64)"),
("完整 Chrome UA",
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 "
"(KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36"),
("Cloudflared", "cloudflared/2026.9.3"),
("空 UA", ""),
]
def probe(name, agent):
headers = {}
if agent is not None:
headers["User-Agent"] = agent
request = urllib.request.Request(URL, headers=headers)
try:
with urllib.request.urlopen(request, timeout=20) as resp:
body = resp.read(200).decode("utf-8", "replace")
return resp.status, body
except urllib.error.HTTPError as exc:
return exc.code, exc.read(200).decode("utf-8", "replace")
except Exception as exc: # noqa: BLE001
return 0, str(exc)
def main() -> int:
print(f" {URL}")
print()
print(f" {'User-Agent':<40}{'HTTP':>6} 响应")
print(" " + "-" * 76)
good = []
for name, agent in AGENTS:
status, body = probe(name, agent)
head = body.strip().replace("\n", " ")[:34]
mark = "✓" if status == 200 else "✗"
print(f" {mark} {name:<38}{status:>6} {head}")
if status == 200:
good.append(name)
print()
if good:
print(f" 能过的:{', '.join(good)}")
print()
print(" 修法:被控端和手表发请求时带上其中一个 UA。")
print(" 用自家标识(LanRemote/1.4.0)比伪装浏览器更合适 ——")
print(" 但如果 Cloudflare 只放行浏览器 UA,那就只能用它。")
else:
print(" 全都过不去 —— 需要在 Cloudflare 面板上关掉 Browser Integrity Check")
return 0
if __name__ == "__main__":
raise SystemExit(main())