我正在尝试确定 android 中 PPTP VPN 接口的名称,以便我可以将其列为我的应用程序中的可绑定接口。由于 Android 中没有 VPN API 可以做到这一点——我想我可以直接使用 Java 来找到它。
当我执行标准 Java 来获取接口列表时,即。
ArrayList<NetworkInterface> allInterfaces = Collections.list(NetworkInterface.getNetworkInterfaces());
我看到一些有趣的事情:
当手机使用 802.11X Wifi 时
- tiwlan0(wifi 接口)
- ppp0(VPN)
当手机仅使用 Verizon 时
- ppp0(VPN) ,通常)
- ppp1 (VZ 网络,通常)
所以 - 我需要一种方法来消除 VZ 接口。您可以像这样从 Android API 获取 NetworkInfo 对象:
ConnectivityManager conMan = (ConnectivityManager)this.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo[] infoList = conMan.getAllNetworkInfo();
该方法存在一些问题:
- VPN 不显示
- Java NetworkInterface 对象中的任何内容都不对应
网络信息对象中的名称/字段与 我发现有几种方法可以从所有接口列表中消除 VZ 接口:
- 按名称执行(即,如果 Android 给了我一个包含“ppp1”的列表,我可以消除 ppp1,因为 Android 列表永远不会包含 VPN)
- 通过 IP 实现(即,如果我能找出 VZ IP 地址,我可以使用 Java 的 NetworkInterface 对象消除与该 IP 的接口。)
不幸的是,这两个选项看起来都不可行,因为名称不匹配,我不知道如何从 Android 操作系统获取 VZ IP。
那么——还有其他人尝试过类似的事情吗?有没有办法询问 android 操作系统哪些接口有 IP 地址?
提前致谢——感谢所有帮助。
丹
PS.我试图避免强迫用户输入要绑定的有效 IP 范围(或特定 IP)。
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 802.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:
- 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)
- 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.
发布评论
评论(2)
编辑:这里的一个可能选项是使用 android 本机工具包进行 JNI 系统调用。读取 /dev/ 的目录列表和 ppp* 的 grep。假设第一个是3G/4G连接,后面一个是VPN。
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.
发现使用当前的 API (10) 不可能做到这一点。错误报告/功能请求:
http://code.google.com/p /android/issues/detail?id=15082
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