Reputation: 5182
I'm currently trying to get a new ip via python.
I found this script on stackoverflow:
import urllib2
from TorCtl import TorCtl
proxy_support = urllib2.ProxyHandler({"http" : "127.0.0.1:8118"})
opener = urllib2.build_opener(proxy_support)
def newId():
conn = TorCtl.connect(controlAddr="127.0.0.1", controlPort=9051, passphrase="123")
conn.send_signal("NEWNYM")
for i in range(0, 10):
print "case "+str(i+1)
newId()
proxy_support = urllib2.ProxyHandler({"http" : "127.0.0.1:8118"})
urllib2.install_opener(opener)
print(urllib2.urlopen("http://www.ifconfig.me/ip").read())
I have my vidalia running and privoxy. I have my settings correctly set:
in system preference (on mac) :
Web Proxy (HTTP): 127.0.0.1:8118 and the same for HTTPS
In my privoxy config file I have this line:
forward-socks5 / 127.0.0.1:9051 .
and in my settings of vidalia I have:
Though still when I run the code it is stuck on on case 1 and I can't get an ip. This is the log of my vidalia:
May 04 19:15:27.381 [Notice] New control connection opened.
May 04 19:15:27.382 [Notice] New control connection opened.
May 04 19:15:33.709 [Notice] New control connection opened.
May 04 19:15:38.653 [Notice] New control connection opened.
May 04 19:15:57.382 [Notice] New control connection opened.
May 04 19:15:57.463 [Notice] New control connection opened.
May 04 19:15:57.464 [Notice] New control connection opened.
May 04 19:16:03.710 [Notice] New control connection opened.
May 04 19:16:19.656 [Notice] New control connection opened.
May 04 19:16:22.448 [Notice] New control connection opened.
May 04 19:16:22.569 [Notice] New control connection opened.
May 04 19:16:22.900 [Notice] New control connection opened.
May 04 19:16:27.382 [Notice] New control connection opened.
May 04 19:16:27.412 [Notice] New control connection opened.
May 04 19:16:27.413 [Notice] New control connection opened.
What am I doing wrong ?
edit:
When the line in the config file is active I can't load any site .
Apparently if I wait long enough I get an error:
urllib2.HTTPError: HTTP Error 503: Forwarding failure
Upvotes: 2
Views: 3478
Reputation: 2954
This question seems to come up pretty frequently (1, 2) so I just added a FAQ entry for it. Tor does not support a method for cycling your IP but it does allow you to create a new identity. Please don't overdo this though, as it puts a high load on the Tor network.
TorCtl is deprecated, so here's an example using stem...
from stem import Signal
from stem.control import Controller
with Controller.from_port(port = 9051) as controller:
controller.authenticate()
controller.signal(Signal.NEWNYM)
Upvotes: 1
Reputation: 5182
its
forward-socks5 / 127.0.0.1:9050 .
not
forward-socks5 / 127.0.0.1:9051 .
Upvotes: 1