refine: not use ping if def interface
This commit is contained in:
+11
-2
@@ -26,9 +26,11 @@ def append_interface(command, pre, interface):
|
|||||||
if not interface_def:
|
if not interface_def:
|
||||||
command += [pre, interface]
|
command += [pre, interface]
|
||||||
|
|
||||||
def check_connectivity_ping(host, interface):
|
def check_connectivity(interface):
|
||||||
|
if not interface_def:
|
||||||
command = ['ping']
|
command = ['ping']
|
||||||
append_interface(command, '-I', interface)
|
append_interface(command, '-I', interface)
|
||||||
|
host = "223.5.5.5"
|
||||||
command += ['-c', '1', host] # -n 1 on windows, -c 1 on linux
|
command += ['-c', '1', host] # -n 1 on windows, -c 1 on linux
|
||||||
try:
|
try:
|
||||||
result = subprocess.check_call(command, timeout=2)
|
result = subprocess.check_call(command, timeout=2)
|
||||||
@@ -41,13 +43,20 @@ def check_connectivity_ping(host, interface):
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"接口 {interface}:Error during ping: {e}")
|
print(f"接口 {interface}:Error during ping: {e}")
|
||||||
return False
|
return False
|
||||||
|
else:
|
||||||
|
try:
|
||||||
|
request_get_text("http://connect.rom.miui.com/generate_204")
|
||||||
|
return True
|
||||||
|
except:
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
device = 0
|
device = 0
|
||||||
if interface_def:
|
if interface_def:
|
||||||
warnings.warn("no interface given by -i or --interface, use default route")
|
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()
|
exit()
|
||||||
|
|
||||||
with open(file, 'r') as f:
|
with open(file, 'r') as f:
|
||||||
|
|||||||
Reference in New Issue
Block a user