Используя Python, как я могу проверить, что SSH-соединение успешно выполнено после следующего:
server = SSHTunnelForwarder(
(host_or_ip, 22),
ssh_username = "ssh_username",
ssh_private_key = path_to_key,
remote_bind_address = (another_host_or_ip, 5432)
)
server.start()
Вы можете сделать это, используя блок try-except
.
ssh_address_or_host = ...
ssh_username = ...
ssh_password = ...
remote_bind_address = ...
try:
with SSHTunnelForwarder(
ssh_address_or_host = ssh_address_or_host,
ssh_username = ssh_username,
ssh_password = ssh_password,
remote_bind_address = remote_bind_address
) as server:
print("connected")
except Exception as e:
print("Non connected because: " + e)