Android - 以编程方式检测 wifi 是否为 WEP、WPA、WPA2 等
Android - detecting if wifi is WEP, WPA, WPA2, etc. programmatically
我正在 Android 上寻找一种编程方式来确定我的设备当前连接的 WIFI 是否 "secured" 使用 WEP、WPA 或 WPA2。我已尝试 Google 搜索,但找不到确定这一点的程序化方法。我还查看了同样缺少此信息的 TelephonyManager (http://developer.android.com/reference/android/telephony/TelephonyManager.html)。
谢谢,
J
有一种方法可以使用 ScanResult 对象。
像这样:
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
}
}
}
}
参考文献:
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
我正在 Android 上寻找一种编程方式来确定我的设备当前连接的 WIFI 是否 "secured" 使用 WEP、WPA 或 WPA2。我已尝试 Google 搜索,但找不到确定这一点的程序化方法。我还查看了同样缺少此信息的 TelephonyManager (http://developer.android.com/reference/android/telephony/TelephonyManager.html)。
谢谢, J
有一种方法可以使用 ScanResult 对象。
像这样:
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
}
}
}
}
参考文献:
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