Files
ykxmz/_build/fix_netcheck_output.py
T
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

162 lines
5.0 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.
# -*- coding: utf-8 -*-
"""给 --netcheck 加个保险:结果同时写一份文件。
为什么:EXE 是 --windowed 打包的,没有控制台。
我用 AllocConsole 自己开了一个,但这类做法在某些情况下
(控制台被系统回收、被杀软拦、权限受限)输出会丢,
用户就只看到一个一闪而过的黑框、什么也没看到。
所以自检结果**同时**写到「网络自检结果.txt」,
wlzj.bat 跑完自动用记事本打开它 —— 不管控制台有没有显示出来,
用户总能拿到结论。
"""
from __future__ import annotations
import sys
from pathlib import Path
ROOT = Path(r"C:\Users\shu\Desktop\deepseekagent\LanRemote")
RUN = ROOT / "windows" / "run_agent.py"
TOOLS = ROOT / "tools"
CLI_OLD = '''def cli_netcheck(seconds: int) -> int:
"""网络自检:监听端口,看手表的包到底有没有到这台电脑。"""
attach_console()
try:
from lanremote import netcheck
return netcheck.run_check(int(seconds or 90))
except Exception as exc: # noqa: BLE001
print(f"自检运行失败: {exc}")
return 1
finally:
wait_key()'''
CLI_NEW = '''class _Tee:
"""把输出同时送到控制台和文件。"""
def __init__(self, *streams):
self.streams = streams
def write(self, text):
for stream in self.streams:
try:
stream.write(text)
stream.flush()
except Exception: # noqa: BLE001
pass
def flush(self):
for stream in self.streams:
try:
stream.flush()
except Exception: # noqa: BLE001
pass
def cli_netcheck(seconds: int) -> int:
"""网络自检:监听端口,看手表的包到底有没有到这台电脑。
EXE 是 --windowed 打包的,本来没有控制台。这里自己开一个,
同时把结果写一份到「网络自检结果.txt」——
控制台万一没显示出来(被杀软拦、权限受限等),
用户还能从文件里看到结论。wlzj.bat 跑完会自动打开这个文件。
"""
attach_console()
original = sys.stdout
path = app_dir() / "网络自检结果.txt"
handle = None
try:
handle = open(path, "w", encoding="utf-8")
except OSError:
handle = None
if handle is not None:
sys.stdout = _Tee(original, handle)
code = 1
try:
from lanremote import netcheck
code = netcheck.run_check(int(seconds or 90))
except Exception as exc: # noqa: BLE001
print(f"自检运行失败: {exc}")
finally:
if handle is not None:
try:
sys.stdout = original
handle.close()
except Exception: # noqa: BLE001
pass
try:
print()
print(f"结果已保存到:{path}")
except Exception: # noqa: BLE001
pass
wait_key()
return code'''
WLZJ = r"""@echo off
chcp 936 >nul
title LAN Remote - Network Self Check
cd /d "%~dp0"
rem 找被控端 exe(脚本可能在 exe 同目录,也可能在子目录)
set "EXE=%~dp0ykxmz.exe"
if not exist "%EXE%" set "EXE=%~dp0..\ykxmz.exe"
if not exist "%EXE%" set "EXE=%~dp0LanRemote-Agent\ykxmz.exe"
if not exist "%EXE%" (
echo.
echo 找不到 ykxmz.exe
echo 请把这个脚本放在被控端目录里运行。
echo.
pause
exit /b 1
)
rem 自检逻辑已经打进 EXE,不需要系统装 Python。
rem /wait:EXE 是图形程序,不加这个 cmd 不会等它跑完。
start "" /wait "%EXE%" --netcheck 90
rem 不管控制台有没有正常显示,结果文件一定有,直接打开给用户看。
if exist "%~dp0网络自检结果.txt" (
start "" notepad "%~dp0网络自检结果.txt"
) else (
echo.
echo 自检跑完了,但没找到「网络自检结果.txt」。
echo 请确认这个脚本和被控端在同一个目录。
echo.
pause
)
exit /b 0
"""
def main() -> int:
text = RUN.read_text(encoding="utf-8")
if "_Tee" in text:
print(" run_agent.py 已经改过")
elif CLI_OLD not in text:
print(" [失败] cli_netcheck 锚点没找到")
return 1
else:
text = text.replace(CLI_OLD, CLI_NEW, 1)
RUN.write_text(text, encoding="utf-8")
print(" cli_netcheck: 现在同时写结果文件")
(TOOLS / "wlzj.bat").write_bytes(
WLZJ.replace("\n", "\r\n").encode("gbk", errors="replace"))
print(" wlzj.bat: 已更新(跑完自动用记事本打开结果)")
import ast
try:
ast.parse(RUN.read_text(encoding="utf-8"))
print(" run_agent.py: 语法 OK")
except SyntaxError as exc:
print(f" run_agent.py: 语法错误 {exc}")
return 1
return 0
if __name__ == "__main__":
sys.exit(main())