如何在SOCKS代理上运行结构脚本?

时间:2011-04-06 13:52:49

标签: python proxy fabric socks

我有一个SOCKS代理设置到网关服务器,该服务器是通过在我的ssh_config中设置主机定义来创建的,以使用DynamicForward localhost:9876。要使用SSH连接到远程服务器,我已设置另一个主机定义以使用ProxyCommand /usr/bin/nc -x localhost:9876 %h %p,这一切都正常。

但是我的结构脚本需要连接到该远程服务器。如何在连接时告诉它使用SOCKS代理?

4 个答案:

答案 0 :(得分:2)

Fabric SSH layer目前不支持网关或代理,但他们“可能会在某个时候修补/ forking以添加该功能。” (来自here)。

还有一个关于Fabric implement tunneling的未解决问题。

This blog post建议覆盖run函数。

答案 1 :(得分:2)

隧道现在(2013年3月)由Fabric本地支持:请参阅导致代码更改的discussioncommit message,并提供一些基本原理。

答案 2 :(得分:0)

您可以使用tsocks和OpenSSH客户端的内置支持来创建SOCKS隧道。它需要一些配置,但它工作正常。以下是我如何开始使用Ubuntu 10.04。

# Install the tsocks library and shell script.
sudo apt-get install tsocks

# Configure the range of IP addresses you need access to.
sudo nano /etc/tsocks.conf

# Use the OpenSSH client to create a socks proxy (stepping
# stones are hosts used to gain access to private subnets).
ssh -D 1080 stepping.stone

# Now connect to any given address in your configured range.
# tsocks will intercept the connection and route it using
# the SOCKS proxy we created with the previous command.
tsocks ssh 1.2.3.4

如果没有VPN连接,Fabric无法正常工作这对我来说是一个交易障碍,所以这是一个很好的解决方案;它需要的是对一个主机的SSH访问。

答案 3 :(得分:0)

{p} Fabric (1.12.0)doc)上的

 env.use_ssh_config = True