简体   繁体   English

Python ssh 客户端通过袜子(代理)

[英]Python ssh client over socks (proxy)

So, I need to connect to SSH server through proxy socks.所以,我需要通过代理袜子连接到 SSH 服务器。 I read paramiko and twisted.conch docs, but didn`t found proxy socks support there.我阅读了 paramiko 和 twisted.conch 文档,但没有在那里找到代理袜子支持。

This socket-wrapper allows you to use static ssh-tunnels.此套接字包装器允许您使用 static ssh 隧道。 I found a common solution for my problem:我为我的问题找到了一个常见的解决方案:

  1. Use paramiko SSHClient class使用 paramiko SSHClient class
  2. Extend SSHClient with your own class用自己的 class 扩展SSHClient
  3. Re-implement the connect() method: Instead of using a standard socket object we pass to it a fixed proxied socket from the python package sockipy重新实现connect()方法:我们不使用标准套接字 object,而是将来自 python package sockipy的固定代理套接字传递给它

Paraproxy (a Paramiko addon for SSH2 ProxyCommands) looks like it can do it. Paraproxy (SSH2 ProxyCommands 的 Paramiko 插件)看起来可以做到。 There's no documentation online but in downloading the source and inspecting the README file, I found this:没有在线文档,但是在下载源代码并检查README文件时,我发现了这一点:

Paraproxy is a supplement to the great "paramiko" SSH2 module. Paraproxy 是对伟大的“paramiko”SSH2 模块的补充。 While paramiko has a really good support for SSH(2) it lacks the ProxyCommand feature.虽然 paramiko 对 SSH(2) 有很好的支持,但它缺少 ProxyCommand 功能。

ProxyCommands can be used eg to connect to VPN tunnels but they provide manny other nice features. ProxyCommands 可用于例如连接到 VPN 隧道,但它们提供许多其他不错的功能。

Paraproxy, once imported will hook into the SSHClient class provided by paramiko which in turn gains full support for SSH ProxyCommands. Paraproxy,一旦导入将连接到由 paramiko 提供的 SSHClient class,从而获得对 SSH ProxyCommands 的完全支持。

No changes to existing code are needed.无需更改现有代码。

Give that a shot!试一试!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM