Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/285.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如果存在两个具有相似SSID的WiFi网络,您如何在代码中区分这两个网络?_C#_.net_Network Programming_Ssid_Wlanapi - Fatal编程技术网

C# 如果存在两个具有相似SSID的WiFi网络,您如何在代码中区分这两个网络?

C# 如果存在两个具有相似SSID的WiFi网络,您如何在代码中区分这两个网络?,c#,.net,network-programming,ssid,wlanapi,C#,.net,Network Programming,Ssid,Wlanapi,我正在写一个小的网络管理工具。为了获取各种WiFi网络的详细信息,我正在调用wlanapi.dll、WlanGetProfile(…)API方法来获取每个可用WiFi网络的配置文件信息 假设两个本地WiFi网络具有相似的SSID,当我向用户提供信息时,如何查询这两个网络上的信息并区分这两个网络 我正在用C#编写我的应用程序,但是,如果他们能给我所需的答案,可以提供非代码特定的一般细节。但是,我将其标记为C#/.Net,因为如果有一种方法可以使用本机.Net库获取此信息,我将非常感谢C#代码示例。

我正在写一个小的网络管理工具。为了获取各种WiFi网络的详细信息,我正在调用
wlanapi.dll、WlanGetProfile(…)
API方法来获取每个可用WiFi网络的配置文件信息

假设两个本地WiFi网络具有相似的SSID,当我向用户提供信息时,如何查询这两个网络上的信息并区分这两个网络


我正在用C#编写我的应用程序,但是,如果他们能给我所需的答案,可以提供非代码特定的一般细节。但是,我将其标记为C#/.Net,因为如果有一种方法可以使用本机.Net库获取此信息,我将非常感谢C#代码示例。

检测具有相同SSID的网络没有问题,因为它们具有不同的MAC


但是,似乎无法连接到选定的网络,因为在连接时无法指定MAC。

具有相同SSID的不同网络仍将具有不同的MAC地址

这也适用于同一网络的不同接入点


不幸的是,我不知道如何查询MAC地址供您检查。

此代码项目示例使用相同的链接:

与mac连接:

//// Connects to a known network with WEP security
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);
////使用WEP安全性连接到已知网络
string profileName=“Cheesecake”//这也是SSID
字符串mac=“52544131303235572D4541374443638”;
string key=“你好”;
string profileXml=string.Format(“{0}{1}{0}ESSopenWEPfalsenetworkKeyfalse{2}0”,profileName,mac,key);
SetProfile(Wlan.WlanProfileFlags.AllUser,profileXml,true);
wlanIface.Connect(Wlan.WlanConnectionMode.Profile,Wlan.Dot11BssType.Any,profileName);

您是否在寻找命令的等效项
netsh wlan show networks mode=bssid
?在C#/powershell中:?WlanGetAvailableNetworkList提供可用网络。除了mac地址之外,我认为识别ssid的频率、通道和通道宽度可能更有用。当我们看到他们在wifi空间中的位置时,用户会更加清楚。(一个是2.4Ghz,另一个是5Ghz?@RLH没有一个答案对你打开悬赏有用吗?该代码应该适用于Xamarin@LiquidCore我已经给了你答案。我把我的奖金留到最后。这是战略性的,也是为了引起注意。无意冒犯。谢谢您的精彩回答。是的,您可以向WlanConnect提供pDesiredBssidList
//// Connects to a known network with WEP security
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);