Home > android, wifi > How to determine wifi network’s security mode

How to determine wifi network’s security mode

A follow-up to an earlier post about adding wifi networks to the known list.

Determining a known wifi network’s security mode can be done like this:

WifiConfiguration wfc = ...

if (wfc.allowedAuthAlgorithms.isEmpty())
{
    // this is an open network
}
else if (wfc.allowedKeyManagement.get(WifiConfiguration.KeyMgmt.NONE))
{
    // WEP network, the key is in wfc.wepKeys[wfc.wepTxKeyIndex]
}
else if (wfc.allowedKeyManagement.get(WifiConfiguration.KeyMgmt.WPA_PSK))
{
    // WPA/WPA2 network, key is in wfc.preSharedKey
}
else
{
    // not one of the above.... weird...
}
Advertisements
Categories: android, wifi
  1. April 13, 2015 at 6:06 pm

    Hi Kostya,

    A lot of changes have happened to android since you posted this example. Can you please thrown some light if any changes have happened to this identification technique or if it is still valid way of checking the security type of a network?

    I am actually working on some app that should call single method “ConnectWiFi” which should accept SSID and passPhrase and be able to connect to n/w of any security type – WEP, WPA, WPA2. Any code samples will be highly appreciated.

    Paritosh

  2. April 13, 2015 at 6:00 pm

    Hi,

    I believe a lot of water has flown under the bridge AFA android is concerned. Can you please tell me how to connect to a WiFi n/w if we don’t already know the security type of the network?

    I am actually working on a library which has a single method accepting ssid and passphrase and can connect to either WEP, WPA or WPA2 type networks.

    • April 13, 2015 at 11:49 pm

      Um, you always know a network’s supported encryption types from scan results — ScanResult#capabilities (String). And as far as I know, it’s still the same in Android 5.1.

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s