mirror of
https://gitee.com/xmz7891/ykxmz.git
synced 2026-10-18 21:50:44 +00:00
被控端 - 修复 MTU 问题:夹 MSS + 路径 MTU 探测(公网可用率 48% -> 100%) - 复用 HTTP 连接(免掉每次新建 TLS 的 30% 握手失败) - 每分钟回头找局域网,自动切回快 400 倍的路径 - 画面心跳帧:静止时省流量,客户端仍知道流是活的 - 锁屏时给出可操作的提示 手表端 - 内置 GTS Root R4 / GlobalSign Root CA,修 SSLHandshakeException - 连接错误翻译成人话(证书/时间/解析/超时分别提示) - 经中转连上后用服务器报的地址刷新已配对记录 - 新增局域网连接页面、服务器延迟检测 服务器端 - 支持 chunked 请求体(修每 16 秒一次的连接错乱与大面积 502) - 网络调优脚本 net-tune.sh(开机自动应用) - 管理页:批量删除、网络体检、下载区 - 隧道改 HTTP/2 + 双连接 文档 - 许可协议 / 安装前必读 / 安装后须知(作者:小麦子)
134 lines
4.4 KiB
Python
134 lines
4.4 KiB
Python
# -*- coding: utf-8 -*-
|
||
"""区分「代理导致的失败」和「真失败」。
|
||
|
||
用户开了代理之后,Windows 这边的测试客户端会受影响:
|
||
WinError 10061 由于目标计算机积极拒绝,无法连接
|
||
这是本机代理拒了连接,不是隧道的问题。
|
||
|
||
这个脚本:
|
||
1. 先看系统代理设置
|
||
2. 绕过代理(proxy=None)直连隧道
|
||
3. 对比走代理 / 不走代理的结果
|
||
"""
|
||
from __future__ import annotations
|
||
|
||
import os
|
||
import socket
|
||
import ssl
|
||
import sys
|
||
import urllib.error
|
||
import urllib.request
|
||
|
||
URL = "https://relay.xxmxxs.top/v1/health"
|
||
UA = {"User-Agent": "LanRemote/1.4.0"}
|
||
|
||
|
||
def show_proxy_settings() -> None:
|
||
print(" 系统代理相关环境变量:")
|
||
found = False
|
||
for name in ("HTTP_PROXY", "HTTPS_PROXY", "ALL_PROXY",
|
||
"http_proxy", "https_proxy", "all_proxy", "NO_PROXY"):
|
||
value = os.environ.get(name)
|
||
if value:
|
||
found = True
|
||
print(f" {name} = {value}")
|
||
if not found:
|
||
print(" (没有代理环境变量)")
|
||
|
||
# Windows 的 IE/系统代理设置(注册表)
|
||
try:
|
||
import winreg
|
||
key = winreg.OpenKey(
|
||
winreg.HKEY_CURRENT_USER,
|
||
r"Software\Microsoft\Windows\CurrentVersion\Internet Settings")
|
||
enable, _ = winreg.QueryValueEx(key, "ProxyEnable")
|
||
try:
|
||
server, _ = winreg.QueryValueEx(key, "ProxyServer")
|
||
except FileNotFoundError:
|
||
server = "(没设)"
|
||
print(f" Windows 系统代理: {'开' if enable else '关'} {server}")
|
||
except Exception: # noqa: BLE001
|
||
print(" (读不到 Windows 代理设置)")
|
||
|
||
|
||
def probe(label: str, opener) -> tuple:
|
||
try:
|
||
with opener() as resp:
|
||
return resp.status, resp.read(60).decode("utf-8", "replace")
|
||
except urllib.error.HTTPError as exc:
|
||
return exc.code, exc.read(60).decode("utf-8", "replace")
|
||
except Exception as exc: # noqa: BLE001
|
||
return 0, f"{type(exc).__name__}: {exc}"
|
||
|
||
|
||
def direct_opener():
|
||
"""完全绕过代理。"""
|
||
handler = urllib.request.ProxyHandler({})
|
||
return urllib.request.build_opener(handler).open(
|
||
urllib.request.Request(URL, headers=UA), timeout=20)
|
||
|
||
|
||
def default_opener():
|
||
"""用系统默认(可能有代理)。"""
|
||
return urllib.request.urlopen(
|
||
urllib.request.Request(URL, headers=UA), timeout=20)
|
||
|
||
|
||
def main() -> int:
|
||
print("=" * 66)
|
||
print(" 代理影响检查")
|
||
print("=" * 66)
|
||
print()
|
||
print("一、当前代理设置")
|
||
show_proxy_settings()
|
||
|
||
print()
|
||
print("二、绕过代理,直连隧道(每种 5 次)")
|
||
direct_ok = 0
|
||
for i in range(1, 6):
|
||
status, body = probe("direct", direct_opener)
|
||
if status == 200:
|
||
direct_ok += 1
|
||
print(f" {i}: HTTP {status} {body[:44]}")
|
||
print(f" 直连成功 {direct_ok}/5")
|
||
|
||
print()
|
||
print("三、用默认设置(可能走代理,5 次)")
|
||
default_ok = 0
|
||
for i in range(1, 6):
|
||
status, body = probe("default", default_opener)
|
||
if status == 200:
|
||
default_ok += 1
|
||
print(f" {i}: HTTP {status} {body[:44]}")
|
||
print(f" 走默认成功 {default_ok}/5")
|
||
|
||
print()
|
||
print("四、TCP 层直连(不经任何 HTTP 代理)")
|
||
try:
|
||
ctx = ssl.create_default_context()
|
||
with socket.create_connection(("relay.xxmxxs.top", 443),
|
||
timeout=15) as raw:
|
||
with ctx.wrap_socket(raw, server_hostname="relay.xxmxxs.top"):
|
||
print(" ✓ TLS 握手成功(说明域名和 443 端口没问题)")
|
||
except Exception as exc: # noqa: BLE001
|
||
print(f" ✗ {type(exc).__name__}: {exc}")
|
||
|
||
print()
|
||
print("=" * 66)
|
||
print(" 结论")
|
||
print("=" * 66)
|
||
if direct_ok > default_ok:
|
||
print(f" 绕过代理更好({direct_ok}/5 vs {default_ok}/5)")
|
||
print(" -> 你的代理在干扰。测试和程序都应该绕开它访问中转。")
|
||
elif direct_ok == default_ok == 5:
|
||
print(" 两种都通 —— 代理没影响")
|
||
elif direct_ok == 0:
|
||
print(" 直连也不通 —— 是隧道/线路的问题,不是代理")
|
||
else:
|
||
print(f" 直连 {direct_ok}/5,默认 {default_ok}/5")
|
||
return 0
|
||
|
||
|
||
if __name__ == "__main__":
|
||
raise SystemExit(main())
|