Is it possible to use Tor network for Java application usage? For example, can I program socket program in Java to use Tor network to hide application data package exchange?

  • Actually all you need is SOCKS5+DNS wrapper, not a special components.
    – Alexey Vesnin
    Dec 27 '15 at 3:46

SilverTunnel-NG is able to provide access to the Tor Network on a Socket level.

You can checkout the Sample code here

The easiest way is to use maven and include the following dependency into your pom.xml:

  • Probably don't use the project. It doesn't appear to use entry guards or many other sane protections.
    – cacahuatl
    Jan 4 '17 at 0:53

I use the following code to have TOR on my Java applications.

System.setProperty("java.net.preferIPv4Stack" , "true");
System.setProperty("socksProxyHost", TOR_IP);
System.setProperty("socksProxyPort", TOR_PORT);

The TOR_IP and TOR_PORT should be "" and "9150" by default if you didn't mess with TOR.

I also managed to find some really old code on how to communicate with TOR to ask for a new identity through Java and created a class for it.

TorControl.java (You should change the constant COOKIE_FILE since I hard coded it)


It is used like this.

TorControl tc=null;
try {
    tc = new TorControl();
} catch (Exception e) {
    System.out.println("Couldn't connect to the TOR control port "+CONTROLPORT);

And then when you want to change your identity simply do tc.newIdentity()

Note: tc.useProxy() will already run the first snippet I posted to make Java run with TOR.

  • You can use PROTOCOLINFO to discover the path of a cookie file, if one is present, rather than hardcoding the path.
    – cacahuatl
    Jan 4 '17 at 0:45
  • Also, are you aware if java handles socks5 properly, IE that it doesn't do the DNS lookups locally? Also there is already github.com/guardianproject/jtorctl for using Tor's control port which you might find more useful, and currently maintained.
    – cacahuatl
    Jan 4 '17 at 1:01
  • I don't remember if this is the one I found, but I remember that I tried to use one but it wouldn't compile, so I just rewrote the part that interested me (new identity). And about the DNS I don't really know. I never looked it up because I only used TOR to get new IPs.
    – user15719
    Jan 4 '17 at 9:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.