Android obtains the currently hidden and unhidden wifi encryption methods (Security)

Source: Internet
Author: User

Android obtains the currently hidden and unhidden wifi encryption methods (Security)
1. General WIFI encryption there are several ways: (1). WPA-PSK/WPA2-PSK (currently the most secure household encryption)
(2). WPA/WPA2 (relatively insecure)
(3). WEP (poor security)

2. Generally, details will pop up when you click on the current network of the system.
How can we obtain this security? You can see from the system source code:

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 = mWifiManager. getConnectionInfo (); // get the configured network connection List
 
  
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", "Current Network Security:" + 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 (KeyMg Mt. IEEE8021X) {return SECURITY_EAP;} return (config. wepKeys [0]! = Null )? SECURITY_WEP: SECURITY_NONE ;}
 

In this way, we can get the result. In this way, you can avoid hiding your Wi-Fi ssid and obtain the encryption method 3. the general encryption method is as follows, but once you set the ssid on the vro to hide it, you cannot find it.
 public void getCipherType(Context context, String ssid) {        WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);        List
 
   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");                    }                }            }        }    }
 



Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.