Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/329.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# 从C获取无线接入点的BSSID(MAC地址)#_C#_Networking_Wireless - Fatal编程技术网

C# 从C获取无线接入点的BSSID(MAC地址)#

C# 从C获取无线接入点的BSSID(MAC地址)#,c#,networking,wireless,C#,Networking,Wireless,如何使用C#获取系统连接到的无线接入点的BSSID/MAC(媒体访问控制)地址 请注意,我对WAP的BSSID感兴趣。这与WAP网络部分的MAC地址不同。以下需要以编程方式执行: netsh wlan show networks mode=Bssid | findstr "BSSID" 上面显示了接入点的无线MAC地址,它不同于: arp -a | findstr 192.168.1.254 这是因为接入点有2个MAC地址。一个用于无线设备,一个用于网络设备。我想要无线MAC,但要使用arp

如何使用C#获取系统连接到的无线接入点的BSSID/MAC(媒体访问控制)地址


请注意,我对WAP的BSSID感兴趣。这与WAP网络部分的MAC地址不同。

以下需要以编程方式执行:

netsh wlan show networks mode=Bssid | findstr "BSSID"
上面显示了接入点的无线MAC地址,它不同于:

arp -a | findstr 192.168.1.254
这是因为接入点有2个MAC地址。一个用于无线设备,一个用于网络设备。我想要无线MAC,但要使用arp的网络MAC

使用:

var-wlanClient=new-wlanClient();
foreach(WlanClient.WlanInterface-WlanClient.Interfaces中的WlanInterface)
{
Wlan.WlanBssEntry[]wlanBssEntries=wlanInterface.GetNetworkBssList();
foreach(Wlan.WlanBssEntry WlanBssEntry中的WlanBssEntry)
{
字节[]macAddr=wlanBssEntry.dot11Bssid;
var macAddrLen=(uint)macAddr.Length;
var str=新字符串[(int)macAddrLen];
for(int i=0;i
关于以编程方式从ARP.EXE获取该结果:

netsh wlan show networks mode=Bssid | findstr "BSSID"
用于获取此信息的Win32 API位于函数组中,它被调用。这个您必须编写一些代码来封送结果,这是一个有趣的具有可变长度结果的Win32 API

另一种方法是使用,它在中有一组很好的包装器类。但缺点是WMI服务必须运行才能正常工作。我已经四处搜索,但似乎在WMI树中找不到包含等效信息的确切对象。我非常肯定它的存在,因为我在网上看到第三方工具声称使用此API检索此信息。也许会有其他人加入到这个角色中来

using System;
using System.Diagnostics;

class Program
{
    static void Main(string[] args)
    {       
        Process proc = new Process();
        proc.StartInfo.CreateNoWindow = true;
        proc.StartInfo.FileName = "cmd";

        proc.StartInfo.Arguments = @"/C ""netsh wlan show networks mode=bssid | findstr BSSID """;

        proc.StartInfo.RedirectStandardOutput = true;       
        proc.StartInfo.UseShellExecute = false;
        proc.Start();
        string output = proc.StandardOutput.ReadToEnd();
        proc.WaitForExit(); 

        Console.WriteLine(output); 
    }   
}
小心像花括号这样的语法错误。但概念就在这里。您可以通过定期调用此过程来创建扫描函数。如果出了问题,请纠正我

C#在Mac电脑上不起作用。我无法抗拒P