品牌标识与握手诊断
- 向导开场:像素字符画 Logo(❯_ 提示符,青绿+光标绿)+ 版本/平台/配置信息 + 横线 - 运行面板头部加 ❯_ 标识;连接中状态改为 ◐◓◑◒ 旋转动画 - SSH banner 错误改为可读诊断文案;握手超时 12→25s;重连日志带尝试次数
This commit is contained in:
@@ -20,6 +20,9 @@ def friendly_error(e: Exception) -> str:
|
||||
return "SSH 认证失败:请检查用户名、密码或私钥。"
|
||||
if isinstance(e, paramiko.SSHException):
|
||||
msg = str(e)
|
||||
if "banner" in msg.lower():
|
||||
return ("SSH 握手失败:已连上端口但对方未回应 SSH 协议"
|
||||
"(远程主机宕机/过载,或端口映射网关异常)")
|
||||
if "negotiation" in msg or "timed out" in msg or "Timeout" in msg:
|
||||
return "SSH 握手超时:远程主机无响应。"
|
||||
if "not a valid" in msg.lower() or ("key" in msg.lower() and "invalid" in msg.lower()):
|
||||
@@ -59,6 +62,7 @@ class Tunnel:
|
||||
self._client: paramiko.SSHClient | None = None
|
||||
self._listener: socket.socket | None = None
|
||||
self._wakeup = threading.Event()
|
||||
self.attempts = 0 # 本次断线后的重试次数
|
||||
|
||||
# ---------- 状态 ----------
|
||||
|
||||
@@ -168,7 +172,7 @@ class Tunnel:
|
||||
port = int(host.get("port") or 22)
|
||||
kw = dict(
|
||||
hostname=host["hostname"], port=port, username=host.get("username"),
|
||||
timeout=12, banner_timeout=12, auth_timeout=12,
|
||||
timeout=15, banner_timeout=25, auth_timeout=15,
|
||||
allow_agent=False, look_for_keys=False,
|
||||
)
|
||||
if host.get("auth") == "key":
|
||||
@@ -177,8 +181,11 @@ class Tunnel:
|
||||
kw["passphrase"] = host["key_passphrase"]
|
||||
else:
|
||||
kw["password"] = host.get("password")
|
||||
self._log("info", f"正在连接 {host.get('username')}@{host['hostname']}:{port} ...")
|
||||
self.attempts += 1
|
||||
n = f"(第 {self.attempts} 次尝试)" if self.attempts > 1 else ""
|
||||
self._log("info", f"正在连接 {host.get('username')}@{host['hostname']}:{port} ... {n}")
|
||||
client.connect(**kw)
|
||||
self.attempts = 0
|
||||
try:
|
||||
client.save_host_keys(str(self.known_hosts_path))
|
||||
except Exception:
|
||||
|
||||
Reference in New Issue
Block a user