Answer the question
In order to leave comments, you need to log in
Local port forwarding with host jumping Python?
Good afternoon!
Help me figure out how to perform port forwarding through multiple hosts in python?
Scheme: [localhost]-[hostA]-[hostB]..[hostN]-[dest_host]
CLI like:
ssh -t -gL 6000:localhost:6000 hostA ssh -t -gL 6000:localhost:6000 hostB ssh -t -gL 6000:dest_host:6000 hostN
from sshtunnel import SSHTunnelForwarder
import requests
with SSHTunnelForwarder(
('192.168.1.3', 22),
ssh_password='password',
ssh_username='username',
local_bind_address=('127.0.0.1', 6000),
remote_bind_address=('dest_host', 6000) # or localhost если сервис тут же
) as server:
headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 6.0; WOW64; rv:24.0) Gecko/20100101 Firefox/24.0'}
r = requests.get('http://127.0.0.1:6000', headers=headers).content
print(r)
Answer the question
In order to leave comments, you need to log in
Dear connoisseurs, Sergey Karbivnichiy Sergey Gornostaev Sergey Pankov , can we really pass by?
Forward sequentially through all tunnels, except for the last one, not port 6000, but 22. The last tunnel will forward the target port. All connections, starting from the second, must be on localhost, and ssh ports will have to be bound to different local ports.
Look, in the CLI you start ssh every time on a new remote machine. Technically, you can do this on one machine, each time attaching port 22 of the next remote machine to the next local port.
Haven't tried it myself. so far no time.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question