在 C# 中连接到无线网络 [英] Connect to a wireless network in C#

查看:32
本文介绍了在 C# 中连接到无线网络的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm using the Managed WiFi API and the example code:

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 和密钥,但我不知道我应该如何获取 MAC 地址.

I updated the code to use my SSID and key, but I don't know how should I get the MAC address.

推荐答案

PhysicalAddress 类应该可以帮到你.MSDN 文章中甚至有一个代码示例,可以从机器上的网络接口中提取 MAC 地址.

The PhysicalAddress class should help you out. There is even a code sample in the MSDN article that extracts a MAC address from the network interfaces on the machine.

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

希望这会有所帮助.

这篇关于在 C# 中连接到无线网络的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆