简体   繁体   English

Tor在python中始终获得唯一的IP

[英]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? 我正试图从py中获取独特的IP,但有时我会得到旧的IP,我已经尝试了50次,延迟5秒,它仍然给我同样的时间,从50次尝试我得到19个重复和31独特,但我希望他的所有时间都变得独特,或者是有限的吗?

I'm using Vidalia Bundle from torproject.org. 我正在使用torproject.org的Vidalia Bundle。

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 :) 让我知道是否有人可以提供帮助,我也想知道是否有可能只从某个国家/地区获得IP并且是唯一的:)

Although The Tor Project recommends against explicitly choosing exit nodes (and may even be removing the feature in future versions), the functionality does exist. 尽管Tor项目建议不要明确选择退出节点(甚至可能在将来的版本中删除该功能),但功能确实存在。 A brief overview can be found on The Tor Project's official FAQ . 可以在The Tor Project的官方常见问题解答中找到简要概述。

The line you are looking for is "ExcludeExitNodes $fingerprint,$fingerprint,...". 您要查找的行是“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. 通过将此行放在您的torrc文件中,并添加您在使用时使用的每个出口节点的指纹,您可以确保每次与Tor的新连接都是新的IP。

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. 只需使用“ExitNodes {cc}”(也在您的torrc中),其中cc是您想要IP的国家/地区的两个字符ISO3166国家/地区代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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