Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

android

wifi

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

like image 881
Jon Avatar asked Mar 06 '15 18:03

Jon


1 Answers

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

like image 133
Daniel Nugent Avatar answered Nov 05 '22 22:11

Daniel Nugent