Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use Tor combine with Java [closed]

Updated my question

I'm building a crawler system by Java to compare price online. However, I worry about my IP address can be banned. So I intend to use proxy to change IP dynamic or use some tools to rotate IP automatically.

Many people said that TOR is a powerful tool to rotate IP. However, I don't know how to use Tor and how to integrate Tor to Java Web Application ?

I've search Google to find example but still find nothing useful.

Anyone can help me.

like image 968
Leo Le Avatar asked Apr 15 '15 15:04

Leo Le


People also ask

Can you use Tor to watch Netflix?

The Tor browser routes your internet traffic through different servers worldwide. Each server adds a layer of encryption and anonymity. However, Tor is not very suitable for streaming Netflix. Because the traffic has to travel through so many “nodes,” Tor can be quite slow.

Should I use Tor for everything?

You can use Tor browser to surf anonymously. However, we strongly discourage you from using just Tor for online protection. Multiple incidents have shown that unsafe use of Tor can result in a severe privacy leak or even issues with your online safety. Think of viruses, criminals, and hacks.


1 Answers

You'll just need to get Java to use the SOCKS4 proxy at localhost:8118 (8118 is the default Tor port) when it makes an outgoing HTTP connection that uses a URL (use URLConnection), while the Tor service is running. See here for how to use proxies in Java 8.

Edit: there is also this pure Java Tor library that you may be able to use, either directly or through minor modification (if it acts entirely like the normal native Tor service), but it hasn't been updated in a while so may not be compatible with the latest Tor specification.

HttpClient example:

HttpHost proxy = new HttpHost("127.0.0.1", 8118, "http");

DefaultHttpClient httpclient = new DefaultHttpClient();
try {
    httpclient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);

    HttpHost target = new HttpHost("www.google.com", 80, "http");
    HttpGet req = new HttpGet("/");

    System.out.println("executing request to " + target + " via " + proxy);
    HttpResponse rsp = httpclient.execute(target, req);
    ...
} finally {
    // When HttpClient instance is no longer needed,
    // shut down the connection manager to ensure
    // immediate deallocation of all system resources
    httpclient.getConnectionManager().shutdown();
}

Note that you must have the Tor service running for this.

like image 121
Chris Dennett Avatar answered Sep 21 '22 19:09

Chris Dennett