简体   繁体   中英

Tor to get always unique IP in python

I'm trying to get unique IP from tor in python but sometimes I'm getting old IPs, I've tried 50 times with a 5 seconds delay as well and its still giving me same sometime, from 50 tries I got 19 duplicates and 31 unique but I want to get unique all he time, Or is tor limited?

I'm using Vidalia Bundle from torproject.org.

I'll type the code I found/modified:

import urllib2
from TorCtl import TorCtl
import time

for i in range(0, 50):
    print "case "+str(i+1)
    conn = TorCtl.connect(passphrase="password11")
    conn.sendAndRecv('signal newnym\r\n')
    conn.close()
    proxy_support = urllib2.ProxyHandler({"http" : "127.0.0.1:8118"})
    urllib2.install_opener(opener)
    print(urllib2.urlopen("http://www.ifconfig.me/ip").read())
    time.sleep(5)

Let me know if anyone can help, also I would like to know if it's possible to get only IPs from a certain country or so and yes unique :)

Although The Tor Project recommends against explicitly choosing exit nodes (and may even be removing the feature in future versions), the functionality does exist. A brief overview can be found on The Tor Project's official FAQ .

The line you are looking for is "ExcludeExitNodes $fingerprint,$fingerprint,...". By putting this line in your torrc file, and adding the fingerprint of every exit node you use as you use them, you can ensure that your IP will be fresh for every new connection to Tor.

As for choosing your country, that is much simpler. Just use "ExitNodes {cc}" (also in your torrc) where cc is the two character ISO3166 country code for the country you'd like an IP from.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM