c# - 在 C# 中连接到无线网络

标签 c# wireless

我正在使用 Managed WiFi API 和示例代码:

string profileName = "Cheesecake"; // this is also the SSID
string mac = "52544131303235572D454137443638";
string key = "hello";
string profileXml = 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, profileXml, true );
wlanIface.Connect( Wlan.WlanConnectionMode.Profile, Wlan.Dot11BssType.Any, profileName );

我更新了代码以使用我的 SSID 和 key ,但我不知道如何获取 MAC 地址。

最佳答案

PhysicalAddress 类应该可以帮助您。 MSDN 文章中甚至有一个代码示例,它从机器上的网络接口(interface)中提取 MAC 地址。

http://msdn.microsoft.com/en-us/library/system.net.networkinformation.physicaladdress.aspx

希望这对您有所帮助。

关于c# - 在 C# 中连接到无线网络,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6318575/

相关文章:

c# - 显示、连接和断开无线网络

python - Xbee API 数据包无法从路由器到达协调器

c - 如何向libnl发送单 channel 扫描请求,并接收相应 channel 的单 channel 扫描完成响应

c - 从混杂的网络设备读取

c# - 如何从另一个类访问具有 protected 构造函数的类

c# - 将泛型对象转换为具有泛型类型接口(interface)的对象

c# - 为什么此 XAML 收到错误 : Items collection must be empty before using ItemsSource

c# - 为什么 Resharper intellisense 会替换我的代码?

c# - 我的 Nullable DateTime View 因 Null 而失败

c# - 如何知道哪些设备连接到我的网络(使用 C#)?