How to block network request of an app using VPNService?

I hope you are doing well.

I am using VPNService in My Application. I created a link https://github.com/hexene/LocalVPN github to create a VPN.

I want to know about a request / response,

How to find out which app is making a request or which app is receiving a response using VPNService.

I want to block some application request to VPNService.

Thanks in advance.

+3


source to share


1 answer


If you just want a simple VpnService that blocks application traffic, without the additional tcp / udp package header handling functionality that LocalVPN offers, you can simply use ToyVPN ( https://android.googlesource.com/platform/development/+/master / samples / ToyVpn ) and use builder.addAllowedApplication or builder.addDisallowedApplication.

ToyVpnConnection.java:



   for (String packageName : mPackages) {
        try {
            if (mAllow) {
                builder.addAllowedApplication(packageName);
            } else {
                builder.addDisallowedApplication(packageName);
            }
        } catch (PackageManager.NameNotFoundException e){
            Log.w(getTag(), "Package not available: " + packageName, e);
        }
    }

      

However, if you need low-level package access, like with LocalVPN, then I'm not sure how. If you do, please post some tips on how to accomplish this, as I am currently trying to figure it out myself!

0


source







All Articles