更新时间:2021-07-10 22:48:06
您可以使用套接字模块,只需检查端口是否打开即可.
You can using the socket module to simply check if a port is open or not.
它看起来像这样.
import socket
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
result = sock.connect_ex(('127.0.0.1',80))
if result == 0:
print "Port is open"
else:
print "Port is not open"
sock.close()