Android教程網
  1. 首頁
  2. Android 技術
  3. Android 手機
  4. Android 系統教程
  5. Android 游戲
 Android教程網 >> Android技術 >> 關於Android編程 >> android 獲取當前隱藏和未隱藏wifi的加密方式(安全性)

android 獲取當前隱藏和未隱藏wifi的加密方式(安全性)

編輯:關於Android編程

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 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 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");
                    }
                }
            }
        }
    }



  1. 上一頁:
  2. 下一頁:
熱門文章
閱讀排行版
Copyright © Android教程網 All Rights Reserved