0

I have the following code in my (test) android project:

        URL u = new URL("http://www.google.com");

        InetSocketAddress sa = InetSocketAddress.createUnresolved("127.0.0.1", 1080);
        Proxy proxy = new Proxy(Proxy.Type.SOCKS, sa);
        HttpURLConnection conn = (HttpURLConnection) u.openConnection(proxy);

Then I have implemented a SOCKS server listening on port 1080.

The problem I have is that in the SOCKS4 connection request, the destination address and port is not "ip for google":80 but rather 127.0.0.1:1080, i.e. the proxy address.

If I return ok, I start getting HTTP data.

Am I doing something wrong or is there a bug in the SOCKS-client?

4

1 回答 1

0

我有一个级别较低但可能对您有用的解决方案:

这适用于我在运行SSHTunnel的根 Nexus 4 上的 Android 4.3 上:

    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);

注意:我还安装了iptables beta,但不确定是否需要。

为此,要与模拟器一起使用,请将 IP 更改为 10.0.2.2,这是您主机的 Android 别名。当然,您必须在您的机器上运行本地 SOCKS 代理。

于 2013-10-21T12:53:02.783 回答