mirror of
https://gitee.com/xmz7891/ykxmz.git
synced 2026-10-18 17:10:43 +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 + 鍙岃繛鎺? 鏂囨。 - 璁稿彲鍗忚 / 瀹夎鍓嶅繀璇?/ 瀹夎鍚庨』鐭ワ紙浣滆€咃細灏忛害瀛愶級
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())
|