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?
2 Answers
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:
<dependency>
<groupId>org.silvertunnel-ng</groupId>
<artifactId>netlib</artifactId>
<version>0.0.4</version>
</dependency>
- 399
- 2
- 7
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 "127.0.0.1" 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();
tc.authenticate();
tc.useProxy();
} 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.