简体   繁体   中英

Using tor browser: how to get an IP address when using SOCKS proxy

I'm trying to use TOR Browser in my code like this:

Proxy proxy = new Proxy(Proxy.Type.SOCKS, new InetSocketAddress("127.0.0.1", 9150));
//add proxy to some other Java class to use
System.out.println(proxy.address()); //127.0.0.1:9150

It would print the locahost address instead of the IP the TOR Browser routes the traffic to. Is there a way to get the later?

It's complicated. Tor can route traffic for different circuits through different paths. So if you open Tor Browser, and go to one domain in a tab and a different domain in a different tab, you'll almost certainly have a different public IP for each tab (this is called stream isolation).

You can associate a SOCKS connection to a stream and then determine the public IP by sniffing events from the Tor controller but the code to do so is not that simple.

Here's another answer where I outline the process: How can I know the IP address of Tor route?

There are also examples in the bottom of that answer for Torbutton that are what show the current tab's circuit path (including the IP addresses of the guard, middle, and exit node).

The easiest (but not necessarily best) way to determine the IP would be to make a request to a site that returns your public IP.

By default though, your requests through Tor's SOCKS proxy are not stream isolated, so they'll all share an IP and be subject to changes if something issues the NEWNYM signal, or if the circuit goes down and builds again using a different path.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM