public static string GetAuthInfo(Wlan.Dot11AuthAlgorithm auth, Wlan.Dot11CipherAlgorithm cipher) { string a = ""; string e = ""; if (auth == Wlan.Dot11AuthAlgorithm.IEEE80211_Open) { a = "open"; } else if (auth == Wlan.Dot11AuthAlgorithm.RSNA_PSK) { a = "WPA2PSK"; } else if (auth == Wlan.Dot11AuthAlgorithm.WPA_PSK) { a = "WPAPSK"; } if (cipher == Wlan.Dot11CipherAlgorithm.WEP) { e = "WEP"; } else if (cipher == Wlan.Dot11CipherAlgorithm.CCMP) { e = "AES"; } return("<authentication>" + a + "</authentication><encryption>" + e + "</encryption>"); }
private string GetAuthenticationType(Wlan.Dot11AuthAlgorithm wlanItemAuthAlgorithmType) { string auth = string.Empty; switch (wlanItemAuthAlgorithmType.ToString()) { case "IEEE80211_Open": auth = "open"; break; case "RSNA": auth = "WPA2PSK"; break; case "RSNA_PSK": //Console.WriteLine("电子设计wifi:》》》"); auth = "WPA2PSK"; break; case "WPA": auth = "WPAPSK"; break; case "WPA_None": auth = "WPAPSK"; break; case "WPA_PSK": auth = "WPAPSK"; break; } return(auth); }
public Wlan.HostedNetworkReason HostedNetworkSecuritySettings(Wlan.Dot11AuthAlgorithm Auth, Wlan.Dot11CipherAlgorithm Cipher) { Wlan.HostedNetworkReason ConfigResult; Wlan.WlanHostedNetworkSecuritySettings settings = new Wlan.WlanHostedNetworkSecuritySettings() { Dot11AuthAlgo = Auth, Dot11CipherAlgo = Cipher }; IntPtr data = Marshal.AllocHGlobal(Marshal.SizeOf(settings)); Marshal.StructureToPtr(settings, data, false); Wlan.WlanHostedNetworkSetProperty(ClientHandle, Wlan.HostedNetworkOpcode.SecuritySettings, (uint)Marshal.SizeOf(settings), data, out ConfigResult, IntPtr.Zero); return(ConfigResult); }
public static string GenerateXmlWLAN(string profileName, string key, Wlan.Dot11AuthAlgorithm auth, Wlan.Dot11CipherAlgorithm cipher) { string mac = StringToHex(profileName); string result = ""; if (cipher == Wlan.Dot11CipherAlgorithm.WEP) { result = 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>{2}<useOneX>false</useOneX></authEncryption><sharedKey><keyType>networkKey</keyType><protected>false</protected><keyMaterial>{3}</keyMaterial></sharedKey><keyIndex>0</keyIndex></security></MSM></WLANProfile>", profileName, mac, GetAuthInfo(auth, cipher), key); } else { result = 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>{2}<useOneX>false</useOneX></authEncryption><sharedKey><keyType>passPhrase</keyType><protected>false</protected><keyMaterial>{3}</keyMaterial></sharedKey><keyIndex>0</keyIndex></security></MSM></WLANProfile>", profileName, mac, GetAuthInfo(auth, cipher), key); } return(result); }
public static string getAuth(Wlan.Dot11AuthAlgorithm authentication) { string auth = string.Empty; switch (authentication.ToString()) { case "IEEE80211_Open": auth = "open"; break; case "IEEE80211_SharedKey": auth = "shared"; break; case "WPA": auth = "WPA"; break; case "WPA_PSK": auth = "WPAPSK"; break; case "RSNA_PSK": auth = "WPA2PSK"; break; } return(auth); }
/// <summary> /// Creates a readable string based on the encryption algorithm and /// the authentication method /// </summary> /// <param name="authentication">authentication used</param> /// <param name="encryption">encryption used</param> /// <returns>a string representing the security mode</returns> public static string CreateSecurityString(Wlan.Dot11AuthAlgorithm authentication, Wlan.Dot11CipherAlgorithm encryption) { String text = authentication + "-" + encryption; text = text.Replace("RSNA", "WPA2"); text = text.Replace("_PSK-CCMP", "-Personal"); text = text.Replace("_PSK-TKIP", "-Personal"); text = text.Replace("CCMP", "Enterprise"); text = text.Replace("IEEE80211_", ""); text = text.Replace("None", ""); text = text.Replace("Open", ""); text = text.Replace("WEP40", "WEP"); text = text.Replace("WEP104", "WEP"); text = text.Trim(new[] { '-' }); if (null == text || text.Equals(String.Empty)) { text = "Open"; } return(text); }
/// <summary> /// Create a valid Profile xml according to: http://msdn.microsoft.com/en-us/library/ms707381(v=VS.85).aspx /// </summary> /// <param name="ssid"></param> /// <param name="key"></param> /// <param name="authAlg"></param> /// <param name="encAlg"></param> /// <returns></returns> internal static string GetProfileXml(string ssid, string key, Wlan.Dot11AuthAlgorithm authAlg, Wlan.Dot11CipherAlgorithm encAlg) { WinProfileAuthenticationEnumeration?auth = null; WinProfileEncryptionEnumeration? enc = null; switch (authAlg) { case Wlan.Dot11AuthAlgorithm.IEEE80211_SharedKey: auth = WinProfileAuthenticationEnumeration.open; enc = WinProfileEncryptionEnumeration.WEP; break; case Wlan.Dot11AuthAlgorithm.WPA_PSK: auth = WinProfileAuthenticationEnumeration.WPAPSK; break; case Wlan.Dot11AuthAlgorithm.RSNA_PSK: auth = WinProfileAuthenticationEnumeration.WPA2PSK; break; } switch (encAlg) { case Wlan.Dot11CipherAlgorithm.TKIP: enc = WinProfileEncryptionEnumeration.TKIP; break; case Wlan.Dot11CipherAlgorithm.CCMP: enc = WinProfileEncryptionEnumeration.AES; break; } if (enc != null && auth != null) { return(string.Format(@"<?xml version=""1.0""?> <WLANProfile xmlns=""http://www.microsoft.com/networking/WLAN/profile/v1""> <name>{0}</name> <SSIDConfig> <SSID> <name>{0}</name> </SSID> </SSIDConfig> <connectionType>ESS</connectionType> <connectionMode>auto</connectionMode> <MSM> <security> <authEncryption> <authentication>{2}</authentication> <encryption>{3}</encryption> <useOneX>false</useOneX> </authEncryption> <sharedKey> <keyType>passPhrase</keyType> <protected>false</protected> <keyMaterial>{1}</keyMaterial> </sharedKey> </security> </MSM> </WLANProfile>", ssid, key, auth.ToString(), enc.ToString())); } else { return(null); } }
void WiFiFound(string bssid, string ssid, int rssi, Wlan.Dot11BssType bssType, Wlan.Dot11AuthAlgorithm authAlg) { ListViewItem lvi = new ListViewItem(bssid); lvi.SubItems.Add(ssid); lvi.SubItems.Add(rssi.ToString()); lvi.SubItems.Add(authAlg.ToString()); listView1.Items.Add(lvi); }