Commit f82da58 authored Mar 13, 2025 Verified
File tree 1 file changed +13
-8
lines changed
1 file changed +13
-8
lines changed Original file line number Diff line number Diff line change 2
2
import platform
3
3
import re
4
4
import socket
5
- import telnetlib
6
5
import time
7
6
8
7
from altfe .interface .root import interRoot
@@ -70,18 +69,24 @@ def get_system_proxy(sys_plc=None):
70
69
def is_local_connect (add , prt ):
71
70
# 检测本地是否可通
72
71
try :
73
- telnetlib .Telnet (add , port = prt , timeout = 1 )
74
- return True
72
+ port = int (port )
73
+ if port >= 0 and port <= 65535 :
74
+ with socket .socket (socket .AF_INET , socket .SOCK_STREAM ) as s :
75
+ s .settimeout (1 )
76
+ return s .connect_ex ((add , port )) == 0
75
77
except :
76
78
return False
77
79
78
80
@staticmethod
79
81
def is_prot_in_use (port ):
80
- port = int (port )
81
- if port >= 0 and port <= 65535 :
82
- with socket .socket (socket .AF_INET , socket .SOCK_STREAM ) as s :
83
- return s .connect_ex (("localhost" , port )) == 0
84
- return False
82
+ try :
83
+ port = int (port )
84
+ if port >= 0 and port <= 65535 :
85
+ with socket .socket (socket .AF_INET , socket .SOCK_STREAM ) as s :
86
+ s .settimeout (1 )
87
+ return s .connect_ex (("localhost" , port )) == 0
88
+ except :
89
+ return False
85
90
86
91
@staticmethod
87
92
def format_time (date_string , style , to = "%Y-%m-%d %H:%M:%S" ):
You can’t perform that action at this time.
0 commit comments