简体   繁体   中英

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:

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. 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. Furthermore, on the terminal page where I am running Tor, it outputs messages like:

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?

According to the Tor control specifications , the NEWNYM signal instructs your tor client to open new circuits. As a result, you will (most likely) get a circuit with a different exit node than before, hence a different IP-address.

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. 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. To minder this, "tor MAY rate-limit the response" to the NEWNYM signal ( section 3.7 of the tor control specification ). 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. 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 ):

HTTPTunnelPort 8118
HTTPTunnelPort 8119 

etc. Then, tor will open one circuit per port on startup, hence this part takes longer. Your requests will have different IP-address, depending on what port you send them. Eg: 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.

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.

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.

Actually i had the same problem, when i use termux to find a password for my forgotton social media. I've use tor first and then a 6k password list. 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?

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