繼this演練我做了以下內容:嘗試安裝和使用torctl但有問題
- 安裝Tor(這樣做手工,而不是通過雙贏的獲得)
- 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'