shanx
shanx

Reputation: 425

Android VpnService 'protect' method not working

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?

Upvotes: 2

Views: 2394

Answers (2)

harry huang
harry huang

Reputation: 61

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.

Upvotes: 0

Robert
Robert

Reputation: 42575

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.

Upvotes: 2

Related Questions