在MSDN上查找相关的配置,大致了解了下这个格式:
<?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>WPAPSK</authentication>
<encryption>TKIP</encryption>
<useOneX>false</useOneX>
</authEncryption>
<sharedKey>
<keyType>passPhrase</keyType>
<protected>false</protected>
<keyMaterial>{1}</keyMaterial>
</sharedKey>
</security>
</MSM>
</WLANProfile>
/// <summary>
/// 连接到未加密的SSID
/// </summary>
/// <param name="ssid"></param>
public WIFISSID ConnectToSSID(string profileName, string key)
{
WIFISSID ssid = null;
Wlan.WlanReasonCode code = Wlan.WlanReasonCode.UNKNOWN;
foreach (WIFISSID s in ssids)
{
if (s.SSID == profileName)
{
ssid = s;
break;
}
}
if (ssid == null) return null;
string mac = StringToHex(profileName); //
switch (ssid.dot11DefaultAuthAlgorithm)
{
case Wlan.Dot11AuthAlgorithm.RSNA_PSK:
string trProfileXml1 = "<?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>WPAPSK</au
thentication><encryption>TKIP</encryption><useOneX>false</useOneX></authEncryption><sharedKey><keyType>passPhrase</keyType><protected>false</protected><keyMa
terial>{1}</keyMaterial></sharedKey></security></MSM></WLANProfile>";
string profileXml = string.Format(trProfileXml1, profileName, key);
code = ssid.wlanInterface.SetProfile(Wlan.WlanProfileFlags.AllUser, profileXml, true);
ssid.wlanInterface.Connect(Wlan.WlanConnectionMode.Profile, Wlan.Dot11BssType.Any, profileName);
break;
default:
break;
}
return ssid;
}
/// <summary>
/// 枚举所有无线设备接收到的SSID
/// </summary>
public void ScanSSID()
{
WlanClient client = new WlanClient();
foreach (WlanClient.WlanInterface wlanIface in client.Interfaces)
{
// Lists all networks with WEP security
Wlan.WlanAvailableNetwork[] networks = wlanIface.GetAvailableNetworkList(0);
foreach (Wlan.WlanAvailableNetwork network in networks)
{
WIFISSID targetSSID = new WIFISSID();
targetSSID.wlanInterface = wlanIface;
targetSSID.wlanSignalQuality = (int)network.wlanSignalQuality;
targetSSID.SSID = GetStringForSSID(network.dot11Ssid);
//targetSSID.SSID = Encoding.Default.GetString(network.dot11Ssid.SSID, 0, (int)network.dot11Ssid.SSIDLength);
targetSSID.dot11DefaultAuthAlgorithm = network.dot11DefaultAuthAlgorithm;
targetSSID.dot11DefaultCipherAlgorithm = network.dot11DefaultCipherAlgorithm.ToString();
Wlan.WlanBssEntry[] bsswork = wlanIface.GetNetworkBssList(network.dot11Ssid, network.dot11BssType, network.securityEnabled);//XP系统这句
会报错
targetSSID.RSSI = bsswork[0].rssi;
ssids.Add(targetSSID);
}
}
} // EnumSSID