Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

How can I get Tor to use a unique IP for each instance of Tor open in C++, Python or Perl? Is there a command to force it to use a unique IP that I can just call using subprocess?

*cheers

share|improve this question

migrated from stackoverflow.com Oct 24 '11 at 16:36

This question came from our site for professional and enthusiast programmers.

    
IIRC recent devel versions of Tor are able to automatically assign different Tor circuits to different SOCKS clients. –  grawity Oct 25 '11 at 9:15

2 Answers 2

You'll need to connect to ToR's control port and issue certain signals to have it create a new connection. You might have to manually check what the end IP is.

This document has some example code in Java and Python for interfacing with ToR along with some of the signals and how to use them. The one you're looking for is probably NEWNYM, but it's not brought up in the linked document. With a little bit of googling, you may be able to find more info on controlling ToR via its control port.

share|improve this answer

Use this in bash:

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

Use this in PHP:

// flush Tor circuit, obtain new IP
$password = '""'; // replace with your Tor password (if any)
exec("(echo authenticate $password; echo signal newnym; echo quit) | nc localhost 9051", $out);
print_r($out);
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.