检索手机中已配置的VPN列表

时间:2019-01-30 15:13:15

标签: java android vpn

我一直在寻找电话上配置的VPN列表很长时间,至少恢复了该名称,但我找不到它。使用NetworkInterface,我已经设法恢复了我所连接的信息,而使用NetworkInfo,我可以获得了连接信息。有什么方法可以恢复我未连接的其他人?

    List<NetworkInterface> interfaces;
    NetworkInterface nVpn;
    String ip = "", hostName ="";
    int e = 0;
    try {
        interfaces = Collections.list(NetworkInterface.getNetworkInterfaces());
        Log.i(TAG, "VPN SIZE: " + interfaces.size());
        for (NetworkInterface ni : interfaces) {
            // Pass over dormant interfaces
            Log.i(TAG, "INTERFACE NAME: " + ni.getName());
            if ("tun0".equals(ni.getName())){
                // The VPN is up
                List<InterfaceAddress> listInterVpn = ni.getInterfaceAddresses();
                for(InterfaceAddress iaVpn : listInterVpn){
                    Log.i(TAG, "VPN IP is: " + iaVpn.getAddress().getHostAddress());
                    Log.i(TAG, "DISPOSITIVE NAME is: " + getHostName(ni.getName()));
                    //IP / Name
                    ip = iaVpn.getAddress().getHostAddress();
                    hostName = iaVpn.getAddress().getHostAddress();
                }
                nVpn = ni;
            }
            if (ni.isUp()){
                Log.i(TAG, "Interface UP name is: " + ni.getName());
            }
        }
    } catch (Exception ex) {
        ex.getMessage();
        Log.i(TAG, "ERROR VPN: " + ex.getMessage());
    }

这将返回我连接的wifi网络和VPN,但不是我在手机中配置的所有内容。

0 个答案:

没有答案