2015-11-13 38 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)。

相關問題