从Ruby脚本获取Tor中的新标识

从Ruby脚本获取Tor中的新标识,ruby,tor,Ruby,Tor,我试图在使用ruby脚本运行Tor时获得新标识,代码取自以下答案: 我的端口是9151,因为我使用的是Tor Bundle。 为了得到一个密码散列,我在终端中编写了tor--hash password hi,它向我返回16:970D11D59DCAC06E6075BED46051146C1EFD9CECDBB3C96A59298422A。 我的TORC文件中相应地有这一行HashedControlPassword 16:970D11D59DCAC06E6075BED46051146C1EFD9C

我试图在使用ruby脚本运行Tor时获得新标识,代码取自以下答案:

我的端口是
9151
,因为我使用的是Tor Bundle。
为了得到一个密码散列,我在终端中编写了
tor--hash password hi
,它向我返回
16:970D11D59DCAC06E6075BED46051146C1EFD9CECDBB3C96A59298422A

我的TORC文件中相应地有这一行
HashedControlPassword 16:970D11D59DCAC06E6075BED46051146C1EFD9CECDBB3C96A59298422A


当我运行我的Ruby脚本时,我得到了
uncaught throw“cannotauthenticate to Tor”
异常抛出。

您必须将密码放在双引号中:

require 'net/telnet'

localhost = Net::Telnet::new("Host" => "localhost", "Port" => "9151", "Timeout" => 10, "Prompt" => /250 OK\n/)
localhost.cmd('AUTHENTICATE hi') { |c| print c; throw "Cannot authenticate to Tor" if c != "250 OK\n" }
localhost.cmd('signal NEWNYM') { |c| print c; throw "Cannot switch Tor to new route" if c != "250 OK\n" }
localhost.close
也就是说,密码是用
或--hash password hi
散列的,但要加上双引号

localhost.cmd('AUTHENTICATE "hi"') { |c| print c; throw "Cannot authenticate to Tor" if c != "250 OK\n" }