使用python sshtunn的隧道

2024-10-04 05:24:47 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试复制命令

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 

Tags: https命令githubcomserverremoteexampleusername
1条回答
网友
1楼 · 发布于 2024-10-04 05:24:47

为什么不使用subprocess并在shell中运行命令呢?你知道吗

for example:

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

这是一个建议,以及取决于你需要用它做什么,如果只是运行命令或你需要做额外的操作!你知道吗

相关问题 更多 >