I'm trying to build a bot but I need it that Tor will change servers every time I refresh the page. I could also use one if I get to manually change it using a command line. Any suggestions?
-
When you say "change servers", do you mean change to a new circuit? Or do you mean change a specific node? For example, a new entry (guard) node, or a new exit node? – Richard Horrocks Nov 15 '15 at 22:03
-
Which platform are you using? (Windows, Linux, Mac OS?) – Richard Horrocks Nov 15 '15 at 22:04
Yes. You can use stem.
Assuming your Tor control port is 9051 and no cookie or password is needed, the following code will initialize a controller object.
import stem
import stem.control
controller=stem.control.Controller.from_port()
controller.authenticate()
Then, each time you want a new circuit, you can use
controller.signal(stem.Signal.NEWNYM)
By default, Tor will only establish a new circuit in this way at most every 10 seconds. If you want to have new circuits more frequently, you will need to changed the source code. MAX_SIGNEWNYM_RATE
means the interval in seconds (although its name suggests the rate) at which it will accept the signal NEWNYM
.