File tree 1 file changed +13
-9
lines changed
1 file changed +13
-9
lines changed Original file line number Diff line number Diff line change @@ -67,21 +67,25 @@ def get_system_proxy(sys_plc=None):
67
67
return ""
68
68
69
69
@staticmethod
70
- def is_local_connect (add , prt ):
71
- # 检测本地是否可通
70
+ def check_port_connection (port , host = "localhost" , timeout = 1 ):
72
71
try :
73
- telnetlib .Telnet (add , port = prt , timeout = 1 )
74
- return True
72
+ port = int (port )
73
+ if port < 0 or port > 65535 :
74
+ return False
75
+
76
+ with socket .socket (socket .AF_INET , socket .SOCK_STREAM ) as s :
77
+ s .settimeout (timeout )
78
+ return s .connect_ex ((host , port )) == 0
75
79
except :
76
80
return False
81
+
82
+ @staticmethod
83
+ def is_local_connect (add , prt ):
84
+ return StaticUtil .check_port_connection (prt , add )
77
85
78
86
@staticmethod
79
87
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
88
+ return StaticUtil .check_port_connection (port )
85
89
86
90
@staticmethod
87
91
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