Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change the Tor exit node programmatically to get a new IP?

Tags:

tor

I have Tor running on my computer, and I need to change the Tor exit node every five minutes. For example, if I start using Tor via some exit node, then in 5 minutes I want Tor to change to an exit node with a different IP address. How can I do this?

Tor, as far as I know, is listening to port 8051 on localhost.

What commands can I send to this port to make Tor build a new chain, so that I can get another IP address?

like image 964
lazybob Avatar asked Dec 28 '09 15:12

lazybob


People also ask

How do I change Tor exit node?

Open the folder where you have installed Tor, browse through browser > Tor browser > Tor > data. There you will find a file named "torrc." Open the file with Notepad. At the end of the document, on a new line, write this: ExitNodes {US}. For example, if you want your exit node to be in China, type {CN}.

What is Tor exit node IP?

Tor exit nodes: A Tor exit node is the last Tor node that traffic passes through in the Tor network before exiting onto the internet. Tor guard nodes: A Tor guard node is the point of entry into the Tor network.

How often do Tor exit nodes change?

ipdata maintains an up-to-date list of the official exit nodes, and combines that with a proprietary list of unofficial Tor IPs. The data is aggregated every 15 minutes and updates every hour, meaning you'll get the most accurate Tor detection possible.

Can a Tor exit node see your IP?

It's analogous to browsing the web through TOR - i.e. the exit node can at most see the IP address of the node immediately before it. The user's IP address is several nodes removed from this node.


1 Answers

Method 1: HUP

sudo killall -HUP tor 

Then check that your IP has changed with:

curl --socks5 127.0.0.1:9050 http://checkip.amazonaws.com/ 

Tested in Ubuntu 17.10 with sudo apt-get install tor version 1.6.0-5.

sudo is needed since the process is started by root by default.

What an HUP signal does exactly to the Tor daemon is documented at: https://gitweb.torproject.org/torspec.git/tree/control-spec.txt?id=03aaace9bd9459b0d4bf22a75012acf39d07bcec#n394 and is equivalent to sending some command through the command port.

Browser Bundle 5.0.5 is not affected by this, only daemon ports like the default 9050, which is not used by the TBB. For that use case see: https://tor.stackexchange.com/questions/1071/how-can-a-new-circuit-happen-without-closing-all-tabs

If you are deploying an army of Tor IPs as mentioned here you can selectively send:

kill -HUP $PID 

Method 2: control port

Mentioned by kat:

(echo authenticate '""'; echo signal newnym; echo quit) | nc localhost 9051 

but for that to work on Ubuntu 17.10 you must first:

  • enable the control port by uncommenting:

    ControlPort 9051 

    from /etc/tor/torrc

  • Set the empty password, otherwise it gives 515 Authentication failed: Wrong length on authentication cookie.. First run:

    tor --hash-password '' 

    This outputs something like:

    16:D14CC89AD7848B8C60093105E8284A2D3AB2CF3C20D95FECA0848CFAD2 

    Now on /etc/tor/torrc update the line:

    HashedControlPassword 16:D14CC89AD7848B8C60093105E8284A2D3AB2CF3C20D95FECA0848CFAD2 
  • Restart Tor:

    sudo service tor restart 

Bonus: how to check that your IP changed

curl --socks5 127.0.0.1:9050 http://checkip.amazonaws.com/ 

See also: https://askubuntu.com/questions/95910/command-for-determining-my-public-ip

Related threads

  • https://superuser.com/questions/449060/tor-how-to-have-different-ip-address-for-every-page-request
  • https://askubuntu.com/questions/499995/change-ip-address-which-is-given-by-tor-using-the-terminal
  • https://tor.stackexchange.com/questions/100/can-tor-be-used-with-applications-other-than-web-browsers
  • https://askubuntu.com/questions/95910/command-for-determining-my-public-ip