mirror of
https://gitee.com/xmz7891/ykxmz.git
synced 2026-10-18 23:00:44 +00:00
琚帶绔?- 淇 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 + 鍙岃繛鎺? 鏂囨。 - 璁稿彲鍗忚 / 瀹夎鍓嶅繀璇?/ 瀹夎鍚庨』鐭ワ紙浣滆€咃細灏忛害瀛愶級
147 lines
4.8 KiB
Python
147 lines
4.8 KiB
Python
# -*- coding: utf-8 -*-
|
|
"""验证「电脑本地剪贴板变化 -> 推送给客户端」。
|
|
|
|
**安全说明**:只用 PowerShell 的 Set-Clipboard,绝不用 ctypes 写剪贴板。
|
|
上一版用 ctypes 时 GlobalAlloc 返回的 64 位句柄被 ctypes 按 32 位 int
|
|
截断,SetClipboardData 拿着坏句柄把系统剪贴板搞成"被占用",
|
|
连 PowerShell 都用不了 —— 那个脚本已经删掉了。
|
|
"""
|
|
from __future__ import annotations
|
|
|
|
import json
|
|
import shutil
|
|
import socket
|
|
import subprocess
|
|
import sys
|
|
import time
|
|
from pathlib import Path
|
|
|
|
ROOT = Path(r"C:\Users\shu\Desktop\deepseekagent\LanRemote")
|
|
EXE = ROOT / "dist_exe" / "ykxmz" / "ykxmz.exe"
|
|
PORT = 8843
|
|
NO_WINDOW = 0x08000000
|
|
|
|
|
|
def set_clipboard(text: str) -> bool:
|
|
"""用 PowerShell 设剪贴板,并等它真的完成。"""
|
|
proc = subprocess.run(
|
|
["powershell", "-NoProfile", "-Command", f"Set-Clipboard -Value '{text}'"],
|
|
capture_output=True, creationflags=NO_WINDOW, timeout=20)
|
|
return proc.returncode == 0
|
|
|
|
|
|
def get_clipboard() -> str:
|
|
proc = subprocess.run(
|
|
["powershell", "-NoProfile", "-Command", "Get-Clipboard -Raw"],
|
|
capture_output=True, creationflags=NO_WINDOW, timeout=20)
|
|
return (proc.stdout or b"").decode("utf-8", "replace").strip()
|
|
|
|
|
|
def main() -> int:
|
|
d = EXE.parent
|
|
real = d / "data"
|
|
bak = None
|
|
if real.exists():
|
|
bak = d / "data_bk_cp2"
|
|
if bak.exists():
|
|
shutil.rmtree(bak, ignore_errors=True)
|
|
shutil.move(str(real), str(bak))
|
|
|
|
proc = None
|
|
try:
|
|
proc = subprocess.Popen(
|
|
[str(EXE), "--port", str(PORT), "--add-device", "10"],
|
|
cwd=str(d), stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
|
|
code = ""
|
|
for _ in range(40):
|
|
time.sleep(0.5)
|
|
try:
|
|
code = json.loads((d / "data" / "settings.json").read_text(
|
|
encoding="utf-8")).get("pairing_code", "")
|
|
except Exception: # noqa: BLE001
|
|
code = ""
|
|
if code:
|
|
try:
|
|
probe = socket.create_connection(("127.0.0.1", PORT), timeout=1)
|
|
probe.close()
|
|
break
|
|
except OSError:
|
|
continue
|
|
|
|
sock = socket.create_connection(("127.0.0.1", PORT), timeout=15)
|
|
sock.settimeout(3)
|
|
buf = b""
|
|
|
|
def send(obj):
|
|
sock.sendall((json.dumps(obj, ensure_ascii=False) + "\n").encode())
|
|
|
|
def read(timeout=3):
|
|
nonlocal buf
|
|
deadline = time.time() + timeout
|
|
while True:
|
|
while b"\n" not in buf:
|
|
if time.time() > deadline:
|
|
return None
|
|
try:
|
|
chunk = sock.recv(65536)
|
|
except (TimeoutError, OSError):
|
|
return None
|
|
if not chunk:
|
|
return None
|
|
buf += chunk
|
|
line, _, buf = buf.partition(b"\n")
|
|
try:
|
|
return json.loads(line.decode("utf-8"))
|
|
except Exception: # noqa: BLE001
|
|
continue
|
|
|
|
send({"cmd": "pair", "deviceId": "cp", "deviceName": "cp", "code": code})
|
|
read(timeout=10)
|
|
print(" 已配对")
|
|
|
|
send({"cmd": "clip_get"})
|
|
print(" 服务端读到的剪贴板: " + str(read(timeout=10)))
|
|
|
|
text = "本地改动-" + str(int(time.time()))
|
|
print(" 用 PowerShell 写入: " + text)
|
|
ok = set_clipboard(text)
|
|
print(" 写入成功: " + str(ok))
|
|
print(" PowerShell 读回: " + get_clipboard())
|
|
|
|
# 等服务端推送
|
|
print(" 等推送…")
|
|
got = None
|
|
deadline = time.time() + 20
|
|
while time.time() < deadline:
|
|
message = read(timeout=2)
|
|
if message is None:
|
|
continue
|
|
if message.get("event") == "clip":
|
|
got = message
|
|
break
|
|
if got:
|
|
print(" ✓ 收到推送: " + str(got)[:100])
|
|
else:
|
|
print(" ✗ 20 秒内没收到 clip 推送")
|
|
sock.close()
|
|
return 0 if got else 1
|
|
finally:
|
|
if proc:
|
|
try:
|
|
proc.terminate()
|
|
proc.wait(timeout=8)
|
|
except Exception: # noqa: BLE001
|
|
try:
|
|
proc.kill()
|
|
except Exception: # noqa: BLE001
|
|
pass
|
|
time.sleep(1)
|
|
if real.exists():
|
|
shutil.rmtree(real, ignore_errors=True)
|
|
if bak and bak.exists():
|
|
shutil.move(str(bak), str(real))
|
|
|
|
|
|
if __name__ == "__main__":
|
|
sys.exit(main())
|