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