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