using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using NativeWifi;
WlanClient client = new WlanClient(); foreach (WlanClient.WlanInterface wlanIface in client.Interfaces) { Wlan.WlanAvailableNetwork[] wlanBssEntries = wlanIface.GetAvailableNetworkList( 0 ); // , istNet.Items.Clear(); foreach (Wlan.WlanAvailableNetwork network in wlanBssEntries) { // ListViewItem listItemWiFi = new ListViewItem(); // , - Trim((char)0) listItemWiFi.Text = System.Text.ASCIIEncoding.ASCII.GetString(network.dot11Ssid.SSID).Trim((char)0); // , . listItemWiFi.SubItems.Add(network.wlanSignalQuality.ToString() + "%"); // listItemWiFi.SubItems.Add(network.dot11DefaultAuthAlgorithm.ToString().Trim((char)0)); // listItemWiFi.SubItems.Add(network.dot11DefaultCipherAlgorithm.ToString().Trim((char)0)); // // listNet.Items.Add(listItemWiFi); } }
try { WlanClient client = new WlanClient(); foreach (WlanClient.WlanInterface wlanIface in client.Interfaces) { Wlan.WlanAvailableNetwork[] wlanBssEntries = wlanIface.GetAvailableNetworkList(0); foreach (Wlan.WlanAvailableNetwork network in wlanBssEntries) { String profileName = System.Text.ASCIIEncoding.ASCII.GetString(network.dot11Ssid.SSID).Trim((char)0); // if (listNet.SelectedItems[0].Text.Equals(profileName)) { String strTemplate=""; String authentication=""; switch ((int)network.dot11DefaultAuthAlgorithm) { case 1: // Open break; case 3: // WEP break; case 4: // WPA_PSK strTemplate = Properties.Resources.WPAPSK; authentication = "WPAPSK"; String encryption = network.dot11DefaultCipherAlgorithm.ToString().Trim((char)0); // String key = "0000000000"; String profileXml = String.Format(strTemplate, profileName, authentication, encryption, key); wlanIface.SetProfile(Wlan.WlanProfileFlags.AllUser, profileXml, true); wlanIface.Connect(Wlan.WlanConnectionMode.Profile, Wlan.Dot11BssType.Any, profileName); break; default: break; } } } } } catch (Exception ex) { MessageBox.Show(ex.Message); }
String profileXml = String.Format(strTemplate, profileName, authentication, encryption, key);
<?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>manual</connectionMode> <MSM> <security> <authEncryption> <authentication>{1}</authentication> <encryption>{2}</encryption> <useOneX>false</useOneX> </authEncryption> <sharedKey> <keyType>passPhrase</keyType> <protected>false</protected> <keyMaterial>{3}</keyMaterial> </sharedKey> </security> </MSM> </WLANProfile>
Source: https://habr.com/ru/post/181251/
All Articles