使用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()
最佳答案
我用它来查看隧道是否打开:
server.skip_tunnel_checkup = False
server.start()
server.check_tunnels()
print(server.tunnel_is_up, flush=True)
在日志中,您将看到:
{('0.0.0.0', 44004): True} # this tunnel is up
{('0.0.0.0', 44004): False} # this tunnel is not up
关于python - Python sshtunnel-如何验证SSH连接?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52070456/