Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Socks proxy in android

Tags:

android

How to Connect SOCKS Proxy connection in android emulator, I am able to connect successfully SOCKS Proxy Server on system browser but it not work in emulator, when using System network setting. I have tried

System.setProperty("socksProxyHost", proxyHost);
System.setProperty("socksProxyPort", port);

and also

SocketAddress addr = new InetSocketAddress(proxyHost, proxyPort);
Proxy httpProxy = new Proxy(Proxy.Type.SOCKS, addr);urlConn = url.openConnection(httpProxy);

but Falied. I want to connect and consume SOCKS Proxy connection & Web Service in my App on Device.Thanks in advance.

like image 712
Sandeep Patidar Avatar asked Aug 28 '13 10:08

Sandeep Patidar


1 Answers

This works for me on Android 4.3 on rooted Nexus 4 with SSHTunnel running:

    SocketAddress proxyAddr = new InetSocketAddress("127.0.0.1", 1984);  
    SocketAddress hostAddr = new InetSocketAddress(address, port);
    java.net.Proxy proxy = new java.net.Proxy(java.net.Proxy.Type.SOCKS, proxyAddr);
    socket = new Socket(proxy);
    socket.connect(hostAddr);

Note: I also installed iptables beta but I'm not sure if it's required.

For this to work with an emulator change the IP to 10.0.2.2 which is Android's alias for your host machine. You will have to run a local SOCKS proxy on your machine of course.

like image 131
Nir Hauser Avatar answered Oct 07 '22 22:10

Nir Hauser