开发者

Determining Android VPN Interface/IP?

开发者 https://www.devze.com 2023-02-13 21:13 出处:网络
I\'m trying to determine the name of a PPTP VPN interface in android so I can list it as a bind-able interface in my application. Since there is no VPN API to do that in Android -- I figured I could u

I'm trying to determine the name of a PPTP VPN interface in android so I can list it as a bind-able interface in my application. Since there is no VPN API to do that in Android -- I figured I could use straight Java to find it.

When I do your standard Java to get the list of interfaces, ie.

ArrayList<NetworkInterface>  allInterfaces = Collections.list(NetworkInterface.getNetworkInterfaces());

I see a few interesting things:

When phone is on 开发者_StackOverflow802.11X Wifi

  • tiwlan0 (the wifi interface)
  • ppp0 (the VPN)

When the phone is on Verizon Only

  • ppp0 (the VPN, usually)
  • ppp1 (the VZ network, usually)

So - I need a way to eliminate the VZ interface. You can get NetworkInfo objects from the Android API like this:

ConnectivityManager conMan = (ConnectivityManager)this.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo[] infoList = conMan.getAllNetworkInfo(); 

There are a few problems with that method:

  • The VPN doesn't show up
  • The names/fields in the network info objects don't correspond to anything in the Java NetworkInterface object

The way I see it there's a few ways to eliminate the VZ interface from the all interfaces list:

  1. Do it by name (ie. if Android gave me a list that had "ppp1" in it I could eliminate ppp1, since the Android list does not ever contain the VPN)
  2. Do it by IP (ie. if I could figure out the VZ IP address, I could eliminate the interface with that IP using Java's NetworkInterface object.)

Unfortunately, it doesn't look like either of those options are possible since the names don't match up and I can't figure out how to get the VZ IP from the Android OS.

So -- has anyone else tried something similar? Is there some way to ask the android OS what interfaces have IP addresses?

Thanks in advance -- all help is appreciated.

Dan

PS. I'm trying to avoid forcing the user to input a valid IP range (or specific IP) to bind to.


EDIT: One possible option here is to do a JNI system calll with the android native kit. Read the directory listing of /dev/ and grep for ppp*. Assume the earliest one is the 3G/4g connection and the latter one is the VPN.


Found out this is not possible using the current API (10). Bug Report/Feature Request:

http://code.google.com/p/android/issues/detail?id=15082

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号