Sandeep Patidar
Sandeep Patidar

Reputation: 287

Socks proxy in 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.

Upvotes: 8

Views: 15904

Answers (2)

dnet
dnet

Reputation: 1429

As far as I know, Android doesn't support SOCKS proxy out of the box, but you can try installing Privoxy, which can act as a HTTP proxy, and it can use a SOCKS upstream proxy. (I used it to hook up the Android emulator to TOR.) You can then set up a HTTP proxy using the UI (so it can be even used on a real phone, not just the emulator). For more information, see my blogpost about Android and TOR.

Upvotes: 1

Nir Hauser
Nir Hauser

Reputation: 31

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.

Upvotes: 2

Related Questions