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
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
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.
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.