Search code examples
torstem

Choose Exit node of Tor Python Stem


How do we choose an exit node of a different country for a Tor controller? I am using python stem library to achieve this. If I use Signal.NEWNYM(), I am able to change exit node's identity but not necessarily its country. Any random exit node of any country would work.


Solution

  • You can achieve this by setting a configuration value for ExitNodes to the countries you want to try to use.

    # tell Tor to try to use exit nodes from USA, Canada and Russia
    my_controller.set_options({
      'ExitNodes': '{US}, {CA}, {RU}'
    })
    

    This isn't really a guarantee. If no exit nodes are available for the countries specified it will fall back. If you change identities frequently there's also good changes you'll end up using the same exits over and over.