Details
-
Bug
-
Status: Open
-
Major
-
Resolution: Unresolved
-
2.0.7
-
None
Description
I'm tring to use Tor to connect using proxy (SOCKS5).
InetSocketAddress resolve dns without use Tor, so i can not use in production.
To use tor to resolve dns i must use InetSocketAddress.createUnresolved.
java.net.Socket work perfectly also with .onion url.
public static void main(String[] args) throws Exception{ NioSocketConnector nioConnector=new NioSocketConnector(); nioConnector.setConnectTimeoutMillis(60000); SocksProxyRequest pr = new SocksProxyRequest( SocksProxyConstants.SOCKS_VERSION_5, SocksProxyConstants.ESTABLISH_TCPIP_STREAM, new InetSocketAddress("www.google.com", 80), ""); ProxyIoSession ps=new ProxyIoSession(new InetSocketAddress("127.0.0.1", 9050), pr); ProxyConnector connector=new ProxyConnector(nioConnector); connector.getFilterChain().addLast("logger", new LoggingFilter()); connector.setProxyIoSession(ps); connector.setHandler(new MyHandler()); ConnectFuture cf=connector.connect(); IoSession session=cf.getSession(); session.getCloseFuture().awaitUninterruptibly(); cf.awaitUninterruptibly(); Thread.sleep(40000); } private static class MyHandler extends AbstractProxyIoHandler { @Override public void proxySessionOpened(IoSession session) { System.out.println("ProxySession aperta"); session.write(IoBuffer.wrap("GET / HTTP/1.0\n\n".getBytes())); } @Override public void messageReceived(IoSession session, Object msg) { System.out.println("Data:"+new String(((IoBuffer)msg).array())); } @Override public void exceptionCaught(IoSession session, Throwable cause) throws Exception { System.out.println("Error: "+cause); } }
=======================================================
public static void main(String[] args) throws Exception{ NioSocketConnector nioConnector=new NioSocketConnector(); nioConnector.setConnectTimeoutMillis(60000); SocksProxyRequest pr = new SocksProxyRequest( SocksProxyConstants.SOCKS_VERSION_5, SocksProxyConstants.ESTABLISH_TCPIP_STREAM, InetSocketAddress.createUnresolved("www.google.com", 80), ""); ProxyIoSession ps=new ProxyIoSession(new InetSocketAddress("127.0.0.1", 9050), pr); ProxyConnector connector=new ProxyConnector(nioConnector); connector.getFilterChain().addLast("logger", new LoggingFilter()); connector.setProxyIoSession(ps); connector.setHandler(new MyHandler()); ConnectFuture cf=connector.connect(); IoSession session=cf.getSession(); session.getCloseFuture().awaitUninterruptibly(); cf.awaitUninterruptibly(); Thread.sleep(40000); } private static class MyHandler extends AbstractProxyIoHandler { @Override public void proxySessionOpened(IoSession session) { System.out.println("ProxySession aperta"); session.write(IoBuffer.wrap("GET / HTTP/1.0\n\n".getBytes())); } @Override public void messageReceived(IoSession session, Object msg) { System.out.println("Data:"+new String(((IoBuffer)msg).array())); } @Override public void exceptionCaught(IoSession session, Throwable cause) throws Exception { System.out.println("Error: "+cause); } }
=========================
java.net.Socket example working with tor.
Socket socket=new Socket(new Proxy(Proxy.Type.SOCKS,new InetSocketAddress("127.0.0.1", 9050))); System.out.println("Tryng connect "); socket.connect(InetSocketAddress.createUnresolved("kpvz7ki2v5agwT35.onion", 80),200000); System.out.println("Connected."); OutputStream os=socket.getOutputStream(); os.write("GET /wiki/index.php/Main_Page HTTP/1.0\n\n".getBytes()); os.flush(); System.out.println("Waiting answer."); System.out.println("Output:"+IOUtils.toString(socket.getInputStream()));
Tell me for other information.
Thank you.