在远程服务器上运行多个ssh会话

0ve6wy6x  于 2021-08-20  发布在  Java
关注(0)|答案(1)|浏览(495)

我试图在连接到跳转服务器后运行多个ssh会话,但是在第10个ip之后,我遇到了超时错误。我需要重新启动ssh会话吗?它不会超过2.44.12.13 ip。

import socket

import paramiko
from jumpssh import SSHSession

# connect to jump server

ssh = paramiko.SSHClient()
gatewaysess=
SSHSession(host="105.111.156.15",username="user",password="Test").open()
print(gatewaysess.is_active())

  list = ["8.40.12.11", "9.40.12.11","9.40.12.18","10.42.12.24", 
            "7.40.12.11","5.40.12.9","6.40.12.8", 
   "8.42.12.1","7.42.12.8","2.44.12.13","1.44.12.38","8.44.12.35","2.40.12.99",
   "2.40.12.19","3.40.12.20"]

for i in list:
   if i == "2.44.12.13":
      remoteses.close()
      remoteses.open()
remoteses = gatewaysess.get_remote_session(i, username="user", 
password="test", look_for_keys=False)
remoteses.is_active())
im9ewurl

im9ewurl1#

最简单、最可靠(虽然不是最有效)的方法是将网关连接移动到环路中。
类似这样(未经测试):

list = ["8.40.12.11", "9.40.12.11","9.40.12.18","10.42.12.24", 
        "7.40.12.11","5.40.12.9","6.40.12.8", 
        "8.42.12.1","7.42.12.8","2.44.12.13","1.44.12.38","8.44.12.35","2.40.12.99",
        "2.40.12.19","3.40.12.20"]

for i in list:
    with SSHSession(host="105.111.156.15",username="user",password="Test") as gatewaysess:
        gatewaysess.open()
        print(gatewaysess.is_active())
        with gatewaysess.get_remote_session(i, username="user", password="test", look_for_keys=False) as remoteses:
            print(remoteses.is_active())

相关问题