Search code examples
geolocationiptor

How can I set the Tor IP to a GeoLocation?


I'm building a bot therefore I want to use Tor. More, I want to set my Ip to chosen Geoloaction or Country. Is this possible?

Heres my Tor initializing code

public static void setUp() throws Exception {
    //driver = new HtmlUnitDriver();    
    //driver = new FirefoxDriver();
    String torPath = "/Applications/TorBrowser.app/Contents/MacOS/firefox";
    String profilePath = "/Applications/TorBrowser.app/TorBrowser/Data/Browser/profile.default/";
    FirefoxProfile profile = new FirefoxProfile(new File(profilePath));
    FirefoxBinary binary = new FirefoxBinary(new File(torPath));
    driver = new FirefoxDriver(binary, profile);        
    baseUrl = "https://qa2all.wordpress.com";
    driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
}

Solution

  • All you have to do is edit the torrc config file used by the Browser Bundle (usually located at Browser/TorBrowser/Data/Tor) and add a config value like so:

    ExitNodes {US}
    

    Where US is the country code of the IP you want to use. You can specify multiples by comma separating them. Note: Country codes must be enclosed by {} in order to work. See the ExcludeNodes documentation for details on what's accepted.