android:确定范围内wifi网络的安全类型(不连接它们) [英] android: Determine security type of wifi networks in range (without connecting to them)

查看:38
本文介绍了android:确定范围内wifi网络的安全类型(不连接它们)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I can enumerate all wifi networks in range (using startScan + SCAN_RESULTS_AVAILABLE_ACTION + getScanResults) and get their SSID and BSSID values, but I can't figure out how to determine the security type of each network.

在我的主要对象中:

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

在我的 scanReceiver 对象中:

In my scanReceiver object:

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

再次在我的主要对象中:

And again in my main object:

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

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

The code works insofar that scanComplete eventually gets called, and I can successfully enumerate all nearby wifi networks and get their SSID and BSSID, but I can't figure out how to determine their security type.

有没有办法做到这一点?

Is there a way to do this?

提前致谢.

推荐答案

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

I think you can find it in the source code of Settings.apk.

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

First you should call wifiManager.getConfiguredNetworks() or wifiManager.getScanResults(), then use the two methods below: (find them in 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网络的安全类型(不连接它们)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆