Ruby Tor Switching Ip - “一般SOCKS服务器故障”,除非我产生一个新进程到telnet到Tor控制端口

时间:2017-08-03 04:24:05

标签: ruby tor socks torsocks

当尝试使用telnet切换Tor IP地址时,我尝试通过telnet连接到Tor控制端口时遇到SOCKSError::ServerFailure: general SOCKS server failure。但是,如果我生成一个新的进程来进行远程登录,我没有问题。我不想生成一个新的过程因为它丑陋。我希望有人可以帮我找到为什么我有这个问题和更多的解决方案?

重现:

开始tor:

tor --SocksPort 9350 --ControlPort 53500 --CookieAuthentication 0 --HashedControlPassword <passwordhash> --DataDirectory /tmp/tor_data/9350

然后运行这个使用socksify设置socks服务器的ruby代码,然后使用tor gem Tor::Controller.connect块通过telnet连接到Tor控制端口来切换Tor端点:

require 'socksify'
require 'terminator'
require 'tor'

TCPSocket::socks_server = "127.0.0.1"
TCPSocket::socks_port = "9350"

Tor::Controller.connect(:port => 53500) do |tor| #<- error
  tor.authenticate("")
  tor.signal("newnym")
end

Tor::Controller.connect来电时出错:

SOCKSError::ServerFailure: general SOCKS server failure

如果我用这个替换Tor::Controller.connect块(生成一个新进程来执行telnet),我就取得了成功:

telnet_pid = nil
begin
  Terminator.terminate :seconds => 20 do
    cmd = "bundle exec ruby -e \"require 'tor'\" -e " +
          "\"Tor::Controller.connect(:port => 53500)" +
          "{|tor| tor.authenticate(''); tor.signal('newnym')}\""
    telnet_pid = Process.spawn(cmd)
    Process.wait telnet_pid
  end
rescue Terminator.error
  puts 'Telnet process to switch Tor endpoint timed out!'
  Process.kill('TERM', telnet_pid) if telnet_pid
end

1 个答案:

答案 0 :(得分:0)

我意识到socks服务器通过SOCKS服务器路由所有TCP请求,包括我的telnet请求。如果我在telnet时禁用socks服务器,然后再次重新启用它,它可以工作:

TCPSocket::socks_server = nil
TCPSocket::socks_port = nil

Tor::Controller.connect(:port => 53500) do |tor| #<- error
  tor.authenticate("")
  tor.signal("newnym")
end

TCPSocket::socks_server = "127.0.0.1"
TCPSocket::socks_port = "9350"