Android - detecting if wifi is WEP, WPA, WPA2, etc. programmatically

你说的曾经没有我的故事 提交于 2019-12-18 20:03:51

问题


I am looking for a programmatic way on Android to determine whether the WIFI my device is currently connected to is "secured" using either WEP, WPA, or WPA2. I've tried Google searching and I cannot find a programmatic way to determine this. I've also looked at the TelephonyManager (http://developer.android.com/reference/android/telephony/TelephonyManager.html) which also lacks this information.

Thanks, J


回答1:


There is a way using the ScanResult object.

Something like this:

WifiManager wifi = (WifiManager) getSystemService(Context.WIFI_SERVICE);
List<ScanResult> networkList = wifi.getScanResults();

//get current connected SSID for comparison to ScanResult
WifiInfo wi = wifi.getConnectionInfo();
String currentSSID = wi.getSSID();

if (networkList != null) {
    for (ScanResult network : networkList) {
        //check if current connected SSID
        if (currentSSID.equals(network.SSID)) {
            //get capabilities of current connection
            String capabilities =  network.capabilities;
            Log.d(TAG, network.SSID + " capabilities : " + capabilities);

            if (capabilities.contains("WPA2")) {
                //do something
            } else if (capabilities.contains("WPA")) {
                //do something
            } else if (capabilities.contains("WEP")) {
                //do something
            }
        }
    }
}

References:

http://developer.android.com/reference/android/net/wifi/WifiManager.html#getScanResults()

http://developer.android.com/reference/android/net/wifi/ScanResult.html#capabilities

http://developer.android.com/reference/android/net/wifi/WifiInfo.html

android: Determine security type of wifi networks in range (without connecting to them)

ScanResult capabilities interpretation




回答2:


Please see AccessPointState class in this project. The method you're looking for is getScanResultSecurity.

Hope it helps!



来源:https://stackoverflow.com/questions/28905604/android-detecting-if-wifi-is-wep-wpa-wpa2-etc-programmatically

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!