从 C# 获取无线接入点的 BSSID(MAC 地址) [英] Get BSSID (MAC address) of wireless access point from C#

查看:19
本文介绍了从 C# 获取无线接入点的 BSSID(MAC 地址)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

How can I get the BSSID / MAC (Media Access Control) address of the wireless access point my system is connected to using C#?

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

Note that I'm interested in the BSSID of the WAP. This is different from the MAC address of the networking portion of the WAP.

推荐答案

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

The following needs to be executed programmatically:

netsh wlan show networks mode=Bssid | findstr "BSSID"

以上显示的是接入点的无线MAC地址,不同于:

The above shows the access point's wireless MAC addresses which is different from:

arp -a | findstr 192.168.1.254

这是因为接入点有 2 个 MAC 地址.一种用于无线设备,一种用于网络设备.我想要无线 MAC,但使用 arp 获取网络 MAC.

This is because the access point has 2 MAC addresses. One for the wireless device and one for the networking device. I want the wireless MAC but get the networking MAC using arp.

使用托管 Wifi API:

var wlanClient = new WlanClient();
foreach (WlanClient.WlanInterface wlanInterface in wlanClient.Interfaces)
{
    Wlan.WlanBssEntry[] wlanBssEntries = wlanInterface.GetNetworkBssList();
    foreach (Wlan.WlanBssEntry wlanBssEntry in wlanBssEntries)
    {
        byte[] macAddr = wlanBssEntry.dot11Bssid;
        var macAddrLen = (uint) macAddr.Length;
        var str = new string[(int) macAddrLen];
        for (int i = 0; i < macAddrLen; i++)
        {
            str[i] = macAddr[i].ToString("x2");
        }
        string mac = string.Join("", str);
        Console.WriteLine(mac);
    }
}

这篇关于从 C# 获取无线接入点的 BSSID(MAC 地址)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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