I am trying to integrate TOR into my java application.

I have tried Silvertunnel and Orchid, and cant get them to work.

I think without doing some learning, im not going to figure this out. On another thread i read

"You'll just need to get Java to use the SOCKS4 proxy at localhost:8118"

Ive started reading into SOCKS4.

Can anyone give some guidance on how to proceed. i.e what should i learn is there a TOR document in need to read( i have been on the TOR site, and cant find a specification document that i need to understand.

Im completely lost about what i need to download how i connect the thing i download to my Java app


2 Answers 2


Just download and run TOR Browser. It will open a socks proxy in your system. You can check the port in browser settings:

enter image description here

You just need to set a proxy for your java socket:

InetSocketAddress HiddenerProxyAddress = new InetSocketAddress("", 9150);
Proxy HiddenProxy = new Proxy(Proxy.Type.SOCKS, HiddenerProxyAddress);
Socket underlying = new Socket(HiddenProxy);
SocketAddress sa = new InetSocketAddress("www.facebook.com", 80);

If you want to connect to a hidden service (onion address), you should create an unresolved socket address:

InetSocketAddress sa = InetSocketAddress.createUnresolved("facebookcorewwwi.onion", 80);

This is it. Now you can connect using socket through TOR.


From the Java client point of view, you have three enpoints in Tor you're interested in communicating with, they are:

  • A SOCKS proxy. It resides at port 9050 on localhost, usually(=by-default). Using it is as simple as using any other SOCKS proxy, so pick a component of your choice or use a built-in functionality according to the official docs. A word of warning and thing that you should explicitly check: use proxy to resolve DNS names. It will prevent the data leaks.
  • A control port with telnet-style command protocol. You may be interested in it not just in case of reading Tor stats and metrics, but also to switch the circuit, i.e. in case when your current one lags as hell. Just AUTHENTICATE xxx there and after 250 OK say SIGNAL NEWNYM - and that's it! Circuits switched! Use any telnet client of your choice, port is 9051 by default, control protocol is described right here
  • A DNS resolver. Of course, you can use it as a DNS server with a very limited functionality, but in conjunction with mapping dot-onion services to private IP ranges - it can be a very good thing to determine "are we going through Tor or not for this hostname".

And one more piece of advice - don't use a surrogates/substitutions for Tor like Silvertunnel, it glitches like hell, actually. Use a standalone tor instance. If a person already have it - just let it betyped in as a config parameter for your app. If the person does not have tor - use expert bundle which is just-a-folder portable distribution of Tor and nothing extra.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .