2015-11-13 41 views
2

this演练我做了以下内容:尝试安装和使用torctl但有问题

  1. 安装Tor(这样做手工,而不是通过双赢的获得)
  2. Privoxy安装

试图运行:

tor --hash-password mypassword 

从命令行我得到

tor is not a recognized command... 

有tor安装。

我的目标是通过Python中的torctl运行tor - 并且能够更改我的IP地址。

运行的示例脚本:

from TorCtl import TorCtl 
import urllib2 

user_agent = 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.7) Gecko/2009021910 Firefox/3.0.7' 
headers={'User-Agent':user_agent} 

def request(url): 
    def _set_urlproxy(): 
     proxy_support = urllib2.ProxyHandler({"http" : "127.0.0.1:8118"}) 
     opener = urllib2.build_opener(proxy_support) 
     urllib2.install_opener(opener) 
    _set_urlproxy() 
    request=urllib2.Request(url, None, headers) 
    return urllib2.urlopen(request).read() 

def renew_connection(): 
    conn = TorCtl.connect(controlAddr="127.0.0.1", controlPort=9051, passphrase="your_password") 
    conn.send_signal("NEWNYM") 
    conn.close() 

for i in range(0, 10): 
    renew_connection() 
    print request("http://icanhazip.com/") 

我得到以下回:

C:\Users\USER>python C:\temp\py_tor.py 
Failed to establish socket: [Errno 10061] No connection could be made because the target machine actively refused it 
Traceback (most recent call last): 
    File "C:\temp\py_tor.py", line 22, in <module> 
    renew_connection() 
    File "C:\temp\py_tor.py", line 18, in renew_connection 
    conn.send_signal("NEWNYM") 
AttributeError: 'NoneType' object has no attribute 'send_signal' 

回答

1

tor --hash-password说,这是无法识别的命令,因为它不是在Windows的PATH环境变量。

只要运行C:\tor\tor.exe替换C:\tor与您安装到的任何位置。

此外,因为你是在Windows上运行tor --hash-password password不会显示任何输出,除非你管它更多,所以你应该使用:

C:\tor\tor.exe --hash-password PASSWORD | more 

错误10061是因为默认情况下,Tor不会在听控制端口9051,因此您需要编辑torrc配置文件并添加ControlPort 9051,以便它将监听您将用于向交换机电路发送NEWNYM信号的控制连接(更改IP)。

相关问题