隧道使用python sshtunnel

问题描述 投票:2回答:1

我试图复制命令

ssh -L8080:127.0.0.1:80 example.com

ssh -R8080:127.0.0.1:80 example.com 

使用python库sshtunnelhttps://github.com/pahaz/sshtunnel/)。

所以我想出了相当于的

ssh -L8080:127.0.0.1:80 example.com

成为

server = SSHTunnelForwarder(
'example.com',
ssh_username="username",
ssh_password="password",
remote_bind_address=('127.0.0.1', 8080))

但我仍然无法理解如何复制命令

ssh -R8080:127.0.0.1:80 example.com 
python ssh-tunnel
1个回答
0
投票

为什么不使用子进程并在shell中运行命令?

for example:

import subprocess
p = subprocess.Popen(["YOUR_COMMAND"], shell=True, stdout=subprocess.PIPE)
p.communicate()

这是一个建议,如果只运行命令或者你需要做额外的操作,还要依赖你需要做什么!

© www.soinside.com 2019 - 2024. All rights reserved.