catch ConnectionRefused also

This commit is contained in:
iwonder 2022-12-01 22:13:31 +01:00
parent 9fbe0a129c
commit 42cc6850b2

View File

@ -22,7 +22,7 @@ def try_connect(ip: str) -> bool:
sock = None
try:
sock = socket.create_connection((ip, 22), 1)
except socket.timeout:
except (socket.timeout, ConnectionRefusedError):
return False
sock.close()
return True
@ -88,6 +88,7 @@ ip = list(filter(lambda x: ip_address(x).version == 4, ips))[0]
while not try_connect(ip):
print('Waiting for SSH service to become available...')
sleep(4)
pass
open_conn(ip)