Question

I am using [VpnService] (http://developer.android.com/reference/android/net/VpnService.html)! and able to create VPN connection. I could see (tracert) all the internet traffic going through VPN.

Now, my requirement is to bypass VPN for certain URLs (eg. www.google.com). To achieve this, I have written the following code:

if (vpnService.protect(new Socket(InetAddress.getByName("74.125.225.241"), 80))) {
    Log.d("TAG", "Socket protection for google.com is successfull");
}

But on visiting www.google.com, I could still see VPN server ip on tracert. So, with this code it seems VpnService is not protecting this request from going to VPN server.

Can anyone point me where I am going wrong and suggest the correct way of doing it?

Was it helpful?

Solution

From my understanding you only exclude (protect) one specific socket from the VPN tunnel.

Therefore every other socket you open with the same target is still going through the VPN tunnel. You have to call protect prepare(...) on every socket that is established from your device towards Google.

OTHER TIPS

You can get to know whether an IP address belongs to a certain URL(such as google.com) by inspecting the DNS query and saving the IP addresses which is linked to the URL you want to bypass. Browsers will start a DNS query first to get the IP address of the domain it want to connect to.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top