我必须连接到Jumpserver,才能连接到仅运行telnet的一堆路由器。我是SSH隧道的新手,但我发现在本地计算机的命令行上,以下命令形成了必要的隧道:
$ ssh -fNL 2300:remote_host:23 user@jumpServer
然后,我要做的就是连接到本地计算机上的端口2300,以将流量转发到路由器上的端口23(该端口没有SSH,只有telnet):
> telnet localhost 2300
我有几个问题:
sshtunnel
模块以编程方式执行此操作?我尝试了以下方法:from sshtunnel import open_tunnel
from telnetlib import Telnet
js = '123.456.555.666'
js_usr = "user"
rem_host = '123.456.789.101'
with open_tunnel(
ssh_address_or_host=(js, 22),
ssh_username=js_usr,
ssh_password="password",
remote_bind_address=(rem_host, 23)
) as tunnel:
with Telnet(js, tunnel.local_bind_port, 10) as tn:
tn.interact()
但是,这会引发以下错误:
我必须连接到Jumpserver,才能连接到仅运行telnet的一堆路由器。我是SSH隧道的新手,但我已经在本地计算机的命令行上发现了以下内容。追踪(最近通话):在第14行的“ C:/Users/somsinha/PycharmProjects/SysTEst/sshTunnelTest.py”文件中使用Telnet(js,tunnel.local_bind_port,10)作为tn:
文件“ C:\ Users \ somsinha \ bin \ WPy64-3741 \ python-3.7.4.amd64 \ lib \ telnetlib.py”,第218行,在[[init]]中self.open(主机,端口,超时)文件“ C:\ Users \ somsinha \ bin \ WPy64-3741 \ python-3.7.4.amd64 \ lib \ telnetlib.py”,第234行,处于打开状态self.sock = socket.create_connection((host,port),timeout)
文件“ C:\ Users \ somsinha \ bin \ WPy64-3741 \ python-3.7.4.amd64 \ lib \ socket.py”,行727,在create_connection中提高错误
文件“ C:\ Users \ somsinha \ bin \ WPy64-3741 \ python-3.7.4.amd64 \ lib \ socket.py”,行716,在create_connection中sock.connect(sa)
ConnectionRefusedError:[WinError 10061]无法建立连接,因为目标计算机主动拒绝了它
如何手动制作python
ssh -fNL 2300:remote_host:23 user@jumpServer
?