简体   繁体   English

通过Tor在Python中使用Stem包时是否可以加快IP地址的更改?

[英]Is it possible to speed up the changing of IP addresses when using theStem package in Python via Tor?

I am currently using the following set-up to change my ip address in Mac OS X:我目前正在使用以下设置来更改我在 Mac OS X 中的 IP 地址:

from stem import Signal
from stem.control import Controller

with Controller.from_port(port = 9051) as controller:
    controller.authenticate()
    controller.signal(Signal.NEWNYM)

headers = {
    'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.13; rv:61.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.135 Safari/537.36 Edge/12.1'
}

proxies = {
    "http": "http://127.0.0.1:8118"
}

r_ip = requests.get("http://icanhazip.com", proxies=proxies, headers=headers_tor)
print(r_ip.text)

I first run Tor in my command line, then execute the above.我首先在我的命令行中运行 Tor,然后执行上面的。 I have noticed that the IP address doesn't change immediately but rather several seconds needs to go by before running the chunk of code above to generate a new ip address.我注意到 IP 地址不会立即更改,而是需要几秒钟才能运行上面的代码块以生成新的 IP 地址。 Furthermore, on the terminal page where I am running Tor, it outputs messages like:此外,在我运行 Tor 的终端页面上,它输出如下消息:

Aug 25 04:13:53.000 [notice] Rate limiting NEWNYM request: delaying by 7 second(s)

Is there a way to change the IP address without a lag?有没有办法在没有延迟的情况下更改 IP 地址?

According to the Tor control specifications , the NEWNYM signal instructs your tor client to open new circuits. 根据Tor控制规范NEWNYM信号指示您的Tor客户打开新电路。 As a result, you will (most likely) get a circuit with a different exit node than before, hence a different IP-address. 结果,您(很可能)将获得一个电路,该电路具有比以前不同的出口节点,因此具有不同的IP地址。

This always needs some time and you cannot really speed up the circuit construction itself. 这总是需要一些时间,您无法真正加快电路构造本身。 What you could do, is changing the "CircuitBuildTimeout" (see the Tor manual ) to something else than the default value of 60 seconds, so if it takes longer than the specified amount of time, tor tries to build a different circuit. 您可以做的是将“ CircuitBuildTimeout”(请参阅Tor手册 )更改为默认值60秒以外的其他值,因此,如果花费的时间超过指定的时间,tor将尝试构建其他电路。 Note, that this might raise privacy issues since you would prefer fast routers. 请注意,这可能会引起隐私问题,因为您更喜欢快速路由器。

The circuit construction always introduces a significant load to the Tor network. 电路结构总是给Tor网络带来很大的负载。 To minder this, "tor MAY rate-limit the response" to the NEWNYM signal ( section 3.7 of the tor control specification ). 要注意的是,“ tor可以对NEWNYM信号进行速率限制”( tor控制规范的3.7节 )。 So you cannot build circuits to often. 因此,您不能经常建立电路。 Apart from changing the source code to disable this mechanism, there is no way to circumvent this intended limitation. 除了更改源代码以禁用此机制之外,没有任何方法可以规避此预期的限制。

If you need a fixed number of different IP addresses, you could specify the "HTTPTunnelPort" config options multiple times with different port. 如果需要固定数量的不同IP地址,则可以使用不同的端口多次指定“ HTTPTunnelPort”配置选项。 For this, you need to add following lines to your torrc file (usually at /etc/tor/torrc for linux.. For Mac, the file seems to be a bit harder to find as descirbed here ): 为此,您需要在torrc文件中添加以下行(对于Linux,通常在/etc/tor/torrc中。对于Mac,该文件似乎更难找到,如此处所述 ):

HTTPTunnelPort 8118
HTTPTunnelPort 8119 

etc. Then, tor will open one circuit per port on startup, hence this part takes longer. 等等,然后,tor将在启动时为每个端口打开一个电路,因此这部分时间更长。 Your requests will have different IP-address, depending on what port you send them. 您的请求将具有不同的IP地址,具体取决于您发送它们的端口。 Eg: port 8118 -> 5.5.5.5 port 8119 -> 4.4.4.4. 例如: port 8118 -> 5.5.5.5 port 8119 -> 4.4.4.4. To switch between the addresses, change the port in the proxy config in your python script. 要在地址之间切换,请在python脚本中更改代理配置中的端口。

This is good for switching between a fixed number of addresses. 这对于在固定数量的地址之间切换非常有用。 However, it only changes when to wait for the circuit construction. 但是,只有在等待电路构建时才改变。 For changing after each request, using NEWNYM seems better. 对于在每次请求后进行更改,使用NEWNYM似乎更好。

Additionally, you can use stem's get_newnym_wait or is_newnym_available to see if tor allows you to build a new circuit and if not, how long you would need to wait. 另外,您可以使用stem的get_newnym_waitis_newnym_available查看tor是否允许您构建新电路,如果不允许,则需要等待多长时间。

Actually i had the same problem, when i use termux to find a password for my forgotton social media.实际上,当我使用 termux 为我忘记的社交媒体查找密码时,我遇到了同样的问题。 I've use tor first and then a 6k password list.我先使用 tor,然后使用 6k 密码列表。 I dont know how to do with this rate limiting.我不知道如何处理这个速率限制。 It kept delaying that only five until ten password that being tested in one night.它一直在推迟一晚只测试五个到十个密码。 It so frustating.这太令人沮丧了。 When i wake up in the morning, i look at my laptop and they still checked the same damn password.当我早上醒来时,我看着我的笔记本电脑,他们仍然检查了同一个该死的密码。 *scream *throw laptop. *尖叫 *扔笔记本电脑。 Is this can be used on termux?这可以在termux上使用吗?

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

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