Compare commits
1 Commits
templates-
...
ssh-fix
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
fa170a6476 |
@@ -467,16 +467,18 @@ def is_ssh_reachable(remote: Remote, opts: ConnectionOptions | None = None) -> b
|
||||
if opts is None:
|
||||
opts = ConnectionOptions()
|
||||
|
||||
address_family = socket.AF_INET6 if ":" in remote.address else socket.AF_INET
|
||||
address_families = [socket.AF_INET, socket.AF_INET6]
|
||||
|
||||
for _ in range(opts.retries):
|
||||
with socket.socket(address_family, socket.SOCK_STREAM) as sock:
|
||||
sock.settimeout(opts.timeout)
|
||||
try:
|
||||
sock.connect((remote.address, remote.port or 22))
|
||||
return True
|
||||
except (TimeoutError, OSError):
|
||||
pass
|
||||
else:
|
||||
time.sleep(opts.timeout)
|
||||
for address_family in address_families:
|
||||
with socket.socket(address_family, socket.SOCK_STREAM) as sock:
|
||||
sock.settimeout(opts.timeout)
|
||||
try:
|
||||
sock.connect((remote.address, remote.port or 22))
|
||||
except (TimeoutError, OSError):
|
||||
continue
|
||||
else:
|
||||
return True
|
||||
time.sleep(opts.timeout)
|
||||
|
||||
return False
|
||||
|
||||
Reference in New Issue
Block a user