refine: not use ping if def interface

This commit is contained in:
lit
2025-06-24 17:13:31 +08:00
parent 5f7aff7d1b
commit 4f2e9a1adf
+11 -2
View File
@@ -26,9 +26,11 @@ def append_interface(command, pre, interface):
if not interface_def:
command += [pre, interface]
def check_connectivity_ping(host, interface):
def check_connectivity(interface):
if not interface_def:
command = ['ping']
append_interface(command, '-I', interface)
host = "223.5.5.5"
command += ['-c', '1', host] # -n 1 on windows, -c 1 on linux
try:
result = subprocess.check_call(command, timeout=2)
@@ -41,13 +43,20 @@ def check_connectivity_ping(host, interface):
except Exception as e:
print(f"接口 {interface}Error during ping: {e}")
return False
else:
try:
request_get_text("http://connect.rom.miui.com/generate_204")
return True
except:
return False
device = 0
if interface_def:
warnings.warn("no interface given by -i or --interface, use default route")
# 检测网络联通性
if check_connectivity_ping("223.5.5.5", interface):
if check_connectivity(interface):
exit()
with open(file, 'r') as f: