使用pythonsshtunnel的隧道

使用pythonsshtunnel的隧道,python,ssh-tunnel,Python,Ssh Tunnel,我正在尝试复制这些命令 ssh -L8080:127.0.0.1:80 example.com 及 使用python库sshtunnel() 所以我找到了 ssh -L8080:127.0.0.1:80 example.com 将来 但我仍然无法理解如何复制该命令 ssh -R8080:127.0.0.1:80 example.com 为什么不使用subprocess并在shell中运行命令 for example: import subprocess p = subprocess.P

我正在尝试复制这些命令

ssh -L8080:127.0.0.1:80 example.com

使用python库
sshtunnel
()

所以我找到了

ssh -L8080:127.0.0.1:80 example.com
将来

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

ssh -R8080:127.0.0.1:80 example.com 

为什么不使用subprocess并在shell中运行命令

for example:

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

这是一个建议,也取决于你需要做什么,如果只是运行命令或你需要做额外的操作

在我看来,您可能混淆了远程端口和本地端口

尝试以下方法:

server = SSHTunnelForwarder(
'example.com',
ssh_username="username",
ssh_password="password",
local_bind_address=('', 8080),
remote_bind_address=('127.0.0.1', 80))
如果您想与所有接口共享远程80端口

或者最好使用:

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

仅为本地接口共享。

欢迎使用SO。你能给你的问题补充一些细节吗?出什么事了?请在此同时发布错误消息或日志文件条目。谢谢。谢谢,我添加了更多的细节。这不是OP要求的,问题是关于一个模块的
server = SSHTunnelForwarder(
'example.com',
ssh_username="username",
ssh_password="password",
local_bind_address=('', 8080),
remote_bind_address=('127.0.0.1', 80))
server = SSHTunnelForwarder(
'example.com',
ssh_username="username",
ssh_password="password",
local_bind_address=('127.0.0.1', 8080),
remote_bind_address=('127.0.0.1', 80))