首页 > 代码库 > android 获取当前隐藏和未隐藏wifi的加密方式(安全性)
android 获取当前隐藏和未隐藏wifi的加密方式(安全性)
1.一般WIFI加密有几种方式:
(1).WPA-PSK/WPA2-PSK(目前最安全家用加密)
(2).WPA/WPA2(较不安全)
(3).WEP(安全较差)
2.一般点击系统当前网络都会有弹出详细信息
那么这个安全性是怎么获取的呢?通过查阅系统源码可知:
public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); WifiManager mWifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE); WifiInfo info = mWifiManager.getConnectionInfo(); // 得到配置好的网络连接 List<WifiConfiguration> wifiConfigList = mWifiManager.getConfiguredNetworks(); for (int i = 0; i < wifiConfigList.size(); i++) { Log.i("hefeng", wifiConfigList.get(i).toString()); Log.i("hefeng", info.getSSID() + "||" + wifiConfigList.get(i).SSID); if (info.getSSID().equals(wifiConfigList.get(i).SSID)) { Log.e("hefeng", "当前网络安全性:" + getSecurity(wifiConfigList.get(i))); } } } /** * These values are matched in string arrays -- changes must be kept in sync */ static final int SECURITY_NONE = 0; static final int SECURITY_WEP = 1; static final int SECURITY_PSK = 2; static final int SECURITY_EAP = 3; 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; }
这样就可以获取到了。这样做可以避免你的wifi ssid被隐藏了还可以获取到加密方式
3.一般获取加密方式是这样的,但是一旦你在路由器上面设置ssid隐藏了,你就搜索不到的
public void getCipherType(Context context, String ssid) { WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); List<ScanResult> list = wifiManager.getScanResults(); for (ScanResult scResult : list) { if (!TextUtils.isEmpty(scResult.SSID) && scResult.SSID.equals(ssid)) { String capabilities = scResult.capabilities; Log.i("hefeng","capabilities=" + capabilities); if (!TextUtils.isEmpty(capabilities)) { if (capabilities.contains("WPA") || capabilities.contains("wpa")) { Log.i("hefeng", "wpa"); } else if (capabilities.contains("WEP") || capabilities.contains("wep")) { Log.i("hefeng", "wep"); } else { Log.i("hefeng", "no"); } } } } }
android 获取当前隐藏和未隐藏wifi的加密方式(安全性)
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。