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

73 lines
2.5 KiB
Python
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.
#!/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())