2

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:

Image

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
4

2 回答 2

1

它的

forward-socks5   /               127.0.0.1:9050 .

不是

forward-socks5   /               127.0.0.1:9051 .
于 2013-05-05T18:21:53.023 回答
1

这个问题似乎经常出现(1 , 2)所以我只是为它添加了一个常见问题解答条目。Tor 不支持循环你的 IP 的方法,但它允许你创建一个新的身份。但请不要过度这样做,因为它会给 Tor 网络带来高负载。

TorCtl 已弃用,所以这里有一个使用stem ...

from stem import Signal
from stem.control import Controller

with Controller.from_port(port = 9051) as controller:
  controller.authenticate()
  controller.signal(Signal.NEWNYM)
于 2013-06-16T03:11:44.933 回答