limit wifi adb reconnect to lightweight ports
This commit is contained in:
1 parent
e3bf99149d
commit
cd7615db3c
6 files changed
+229
-31
No files matched your search
@@ -86,6 +86,18 @@ def try_reconnect_last_wifi(
|
||||
on_line(f"[启动] 尝试重连上次的 WiFi 设备: {target} ...")
|
||||
|
||||
def worker():
|
||||
light_ports: list[int] = []
|
||||
last_ip = ""
|
||||
try:
|
||||
if ":" in target:
|
||||
last_ip, port_s = target.rsplit(":", 1)
|
||||
light_ports.append(int(port_s))
|
||||
except Exception:
|
||||
last_ip = ""
|
||||
for candidate in (5555, 44219):
|
||||
if candidate not in light_ports:
|
||||
light_ports.append(candidate)
|
||||
|
||||
# 先直连
|
||||
state, msg = "failed", ""
|
||||
try:
|
||||
@@ -112,6 +124,34 @@ def try_reconnect_last_wifi(
|
||||
_safe_after(root, render_unauth, fallback=render_unauth)
|
||||
return
|
||||
|
||||
# 先对同一个 IP 做轻量端口探测,避免直接进子网扫描。
|
||||
if last_ip and light_ports:
|
||||
for probe_port in light_ports:
|
||||
probe_target = f"{last_ip}:{probe_port}"
|
||||
if probe_target == target:
|
||||
continue
|
||||
try:
|
||||
probe_state, _probe_msg = verify_adb_target(adb_exe, probe_target)
|
||||
except Exception:
|
||||
probe_state = "failed"
|
||||
if probe_state != "connected":
|
||||
continue
|
||||
|
||||
def render_same_ip_hit(probe_target=probe_target):
|
||||
refresh_devices()
|
||||
device_var.set(probe_target)
|
||||
try:
|
||||
set_last_wifi_target(probe_target, model)
|
||||
except Exception:
|
||||
pass
|
||||
on_line(
|
||||
f"[启动] 上次 IP 命中轻量端口 {probe_target}"
|
||||
+ (f" ({model})" if model else "")
|
||||
)
|
||||
|
||||
_safe_after(root, render_same_ip_hit, fallback=render_same_ip_hit)
|
||||
return
|
||||
|
||||
# state == "failed" → 不可达。换网了?自动扫一下,看能不能在新网段找到
|
||||
def notify_scan_start():
|
||||
on_line(
|
||||
@@ -120,8 +160,8 @@ def try_reconnect_last_wifi(
|
||||
_safe_after(root, notify_scan_start, fallback=notify_scan_start)
|
||||
|
||||
try:
|
||||
# 自动模式会先验证上次目标,再对在线候选主机补扫完整端口段。
|
||||
devs = discover_adb_devices(adb_exe)
|
||||
# 自动模式先对同 IP 轻量探测,失败后再对子网做轻量候选端口发现。
|
||||
devs = discover_adb_devices(adb_exe, ports=light_ports)
|
||||
except Exception as e:
|
||||
def render_scan_err():
|
||||
on_line(f"[启动] 自动扫描失败: {e}")
|
||||
|
||||
Reference in new issue
Block a user