android:确定范围内wifi网络的安全类型(不连接它们)

标签 android security wifi android-wifi

我可以枚举范围内的所有 wifi 网络(使用 startScan + SCAN_RESULTS_AVAILABLE_ACTION + getScanResults)并获取它们的 SSID 和 BSSID 值,但我不知道如何确定每个网络的安全类型。

在我的主要对象中:

    IntentFilter intentFilter = new IntentFilter();
    intentFilter.addAction(WifiManager.SCAN_RESULTS_AVAILABLE_ACTION);
    registerReceiver(scanReceiver, intentFilter);
    ((WifiManager)getSystemService(Context.WIFI_SERVICE)).startScan();

在我的 scanReceiver 对象中:

public void onReceive(Context c, Intent intent) {
    if (WifiManager.SCAN_RESULTS_AVAILABLE_ACTION.equals(intent.getAction())){
        mainObject.scanComplete();
    }
}

再次在我的主要对象中:

public void scanComplete()
{
    List<ScanResult> networkList = ((WifiManager)getSystemService.(Context.WIFI_SERVICE)).getScanResults();
    for (ScanResult network : networkList)
    {
        <do stuff>
    }
}

代码在 scanComplete 最终被调用的范围内工作,我可以成功枚举附近的所有 wifi 网络并获取它们的 SSID 和 BSSID,但我不知道如何确定它们的安全类型。

有没有办法做到这一点?

提前致谢。

最佳答案

我想你可以在 Settings.apk 的源代码中找到它。

首先你应该调用 wifiManager.getConfiguredNetworks()wifiManager.getScanResults(), 然后使用以下两种方法:(在AccessPoint class "com.android.settings.wifi"中找到它们):

static int getSecurity(WifiConfiguration config) {
    if (config.allowedKeyManagement.get(KeyMgmt.WPA_PSK)) {
        return SECURITY_PSK;
    }
    if (config.allowedKeyManagement.get(KeyMgmt.WPA_EAP) ||
            config.allowedKeyManagement.get(KeyMgmt.IEEE8021X)) {
        return SECURITY_EAP;
    }
    return (config.wepKeys[0] != null) ? SECURITY_WEP : SECURITY_NONE;
}

static int getSecurity(ScanResult result) {
    if (result.capabilities.contains("WEP")) {
        return SECURITY_WEP;
    } else if (result.capabilities.contains("PSK")) {
        return SECURITY_PSK;
    } else if (result.capabilities.contains("EAP")) {
        return SECURITY_EAP;
    }
    return SECURITY_NONE;
}

希望这有帮助。

关于android:确定范围内wifi网络的安全类型(不连接它们),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6866153/

相关文章:

iphone - 从 iPhone 应用程序通过 WIFI 将文件导出到计算机 -

android - (android)如何判断android热点中已连接设备的ip地址

android - 为智能手机编写wifi设备驱动程序

android - 如果我在操作栏中隐藏图标或应用程序名称,为什么栏会改变它们的位置

android - 从 android Activity 执行 su 命令

security - 对heroku postgresql DB的访问只能仅限于它的heroku应用程序吗?

java - Google New Places API - 您的应用程序包含公开的 Google Cloud Platform

wordpress - 如何处理 Docker 镜像中的安全更新?

android - 如何在android中实现从/到excel导入/导出sqlite数据

android - SQL:带有外键的交叉表到两个不同的表