#!/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()