2016-11-26 157 views
0

我想將我的網絡與AES加密和WPA2安全性連接起來。但是當我刪除網絡並嘗試重新連接我的程序時,我失敗了。我錯過了什麼?如何使用C#中的ManagedWifi連接到未知的WPA-WPA2網絡

WlanClient client = new WlanClient(); 

foreach (WlanClient.WlanInterface wlanIface in client.Interfaces) 
{ 

    Wlan.WlanAvailableNetwork[] networks = wlanIface.GetAvailableNetworkList(0);  
    string ssid = GetStringForSSID(networks[0].dot11Ssid); 
    byte[] ssidBytes = System.Text.Encoding.Default.GetBytes(ssid); 
    string ssidHex = BitConverter.ToString(ssidBytes); 
    ssidHex = ssidHex.Replace("-", "");  
    string profileName = GetStringForSSID(networks[0].dot11Ssid); 
    string mac = ssidHex; 
    string key = "**PASSWORD**"; 
    string profile = string.Format("<?xml version=\"1.0\"?><WLANProfile xmlns=\"http://www.microsoft.com/networking/WLAN/profile/v1\"><name>{0}</name> <SSIDConfig><SSID><hex>{1}</hex><name>{0}</name></SSID></SSIDConfig> <connectionType>ESS</connectionType><MSM><security><authEncryption><authentication>open</authentication><encryption>WEP</encryption><useOneX>false</useOneX></authEncryption><sharedKey><keyType>networkKey</keyType><protected>false</protected><keyMaterial>{2}</keyMaterial></sharedKey><keyIndex>0</keyIndex></security></MSM></WLANProfile>", 
    profileName, mac, key); 
    wlanIface.SetProfile(Wlan.WlanProfileFlags.AllUser, profile, true); 
    wlanIface.Connect(Wlan.WlanConnectionMode.Profile, Wlan.Dot11BssType.Any, profileName); 

} 

回答

0

你說,你

[...]要連接我的網絡使用AES加密和WPA2的安全性。

反正看你的個人資料,您所配置的設備WEP

<security> 
    <authEncryption> 
    <authentication>open</authentication> 
    <encryption>WEP</encryption> <!-- see here --> 
    <useOneX>false</useOneX> 
    </authEncryption> 
    <sharedKey> 
    <keyType>networkKey</keyType> 
    <protected>false</protected> 
    <keyMaterial>**PASSWORD**</keyMaterial> 
    </sharedKey> 
    <keyIndex>0</keyIndex> 
</security> 

我已經成功地建立與下面的配置

<security> 
    <authEncryption> 
     <authentication>WPA2PSK</authentication> 
     <encryption>AES</encryption> 
     <useOneX>false</useOneX> 
    </authEncryption> 
    <sharedKey> 
     <keyType>passPhrase</keyType> 
     <protected>false</protected> 
     <keyMaterial>**PASSWORD**</keyMaterial> 
    </sharedKey> 
</security> 
一個WPA2(PSK)連接