views:

9474

answers:

5

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

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.

+2  A: 

This question tells how to get any bit of information you want out of your network connection. (Scroll down to the answers using NetworkInformation)

James Curran
+2  A: 

The following needs to be executed programmatically:

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

The above shows the WAP Wireless MAC addresses which is different from:

arp -a | findstr 192.168.1.254

This is because the WAP 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.

Using the Manager 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);
    }
}
Iain
+1  A: 

About getting that result from ARP.EXE programmatically:

The Win32 API to get this is in the IP Helper group of functions and it is called GetIpNetTable(). The P/Invoke signature for it is here. You'll have to write some code to marshal the results out of it, and its one of those fun Win32 APIs with variable length results.

Another way to do this would be to use Windows Management Instrumentation which does have a nice set of wrapper classes in the System.Management and System.Management.Instrumentation namespaces. But the down side is the WMI service must be running for that to work. I've dug around but I can't seem to find the exact object in the WMI tree that contains the equivalent information. I'm pretty sure it exists because I see third-party tools on the net that claim to retrieve this info using this API. Maybe someone else will chime in with that part.

Tim Farley
A: 

Hello, how can I obtain what computers are connected om my router? I tried to use this method, but I realize that I obtain only MAC Address of my ROUTER, and I want to know MAC Address of others computers connected on this router. let me know if I can explain my doubt.

Cheeers,

Michel Trettim

Michel, welcome to Stack Overflow! Best to this ask this as a new question to get a response.
Iain
A: 

Hey...is there a possibility to get the list of the whole BSSID of the close up Access Points, too?

isicom
Hey Isicom, Welcome to Stack Overflow! You're much more likely to get an answer if you pose that as a new question.
Iain
I already pose the question in a new question before...see question: 'Get the list of all SSIDs and their mac address' thanx
isicom