gpt4 book ai didi

Android - 以编程方式检测 wifi 是否为 WEP、WPA、WPA2 等

转载 作者:塔克拉玛干 更新时间:2023-11-02 07:55:48 26 4
gpt4 key购买 nike

我正在寻找一种在 Android 上使用 WEP、WPA 或 WPA2 来确定我的设备当前连接到的 WIFI 是否“安全”的编程方式。我试过谷歌搜索,但找不到确定这一点的程序化方法。我还查看了同样缺少此信息的 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 是否为 WEP、WPA、WPA2 等,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28905604/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com