code-dumps/py/port-test.py

16 lines
418 B
Python
Raw Normal View History

2024-03-06 09:51:53 +08:00
#!/usr/bin/python3
import socket
hosts=['192.168.86.51', '192.168.86.53']
port=22
timeout_seconds=1
for host in hosts:
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.settimeout(timeout_seconds)
result = sock.connect_ex((host,int(port)))
if result == 0:
print("Host {}:{} - Up".format(host, port))
else:
print("Host {}:{} - Down".format(host, port))
sock.close()