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>
-
Probably don't use the project. It doesn't appear to use entry guards or many other sane protections. Commented Jan 4, 2017 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 "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.
-
You can use
PROTOCOLINFO
to discover the path of a cookie file, if one is present, rather than hardcoding the path. Commented Jan 4, 2017 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. Commented Jan 4, 2017 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.– user15719Commented Jan 4, 2017 at 9:39