gpt4 book ai didi

python - Python sshtunnel-如何验证SSH连接?

转载 作者:行者123 更新时间:2023-12-02 14:00:57 25 4
gpt4 key购买 nike

使用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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com