I am trying to determine the PPTP VPN interface name in android, so I can list it as the connecting interface in my application. Since Android does not have a VPN API, I decided that I could use direct Java to find it.
When I do your standard Java to get a list of interfaces i.e.
ArrayList<NetworkInterface> allInterfaces = Collections.list(NetworkInterface.getNetworkInterfaces());
I see some interesting things:
When the phone is connected to Wi-Fi 802.11X
- tiwlan0 (wifi interface)
- ppp0 (VPN)
When the phone is only on Verizon
- ppp0 (usually VPN)
- ppp1 (usually a VZ network)
So - I need a way to eliminate the VZ interface. You can get NetworkInfo objects from the Android API as follows:
ConnectivityManager conMan = (ConnectivityManager)this.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo[] infoList = conMan.getAllNetworkInfo();
There are several problems with this method:
- VPN is not displayed
- Names / fields in network information objects do not match anything in the Java NetworkInterface object
As I see, there are several ways to remove the VZ interface from the list of all interfaces:
- Do it by name (i.e. if Android gave me a list that had "ppp1" in it, I could remove ppp1, since the Android list never contains a VPN)
- Do this by IP (i.e. if I could find the VZ IP address, I could exclude the interface with that IP address using the Java NetworkInterface object.)
Unfortunately, it does not look like either of these options is possible, as the names do not match, and I cannot figure out how to get the VZ IP from Android OS.
So - has anyone else tried something like this? Is there any way to ask android OS which interfaces have IP addresses?
Thanks in advance - all help is appreciated.
Dan
PS. I try not to force the user to enter a valid IP range (or a specific IP) for binding.
source share