Find the MAC of current AP

Feb 4, 2013 at 8:54 PM
I'm trying to find the MAC of my currently connected AP. I'm working on a program that will show the current AP MAC while roaming from AP to AP.

I found this example to get the MAC of all AP's visible but I don't understand how to specify only the AP I am connected to.

http://managedwifi.codeplex.com/discussions/398107

I hope someone can help.

Using VB.NET. But C# is ok too.

thanks
Feb 28, 2013 at 6:03 PM
I need to do the EXACT same thing (which is a big deal because it seems like no one else in the world needs to do this).

Were you ever able to figure anything out about this? Are you still working on it/interested in a solution?

Can anyone who knows this API well, just say if it is even possible (through this api) to find the BSSID/mac of the specific layer 2 WAP that you are connected to the SSID through?
Mar 4, 2013 at 6:08 PM
I found a couple ways to do it. The first one is using Managed WIFI.
'Make sure you add a reference to the ManagedWifi.dll
Imports NativeWifi
Imports System.Text
Public Class Form1
    Private Sub btnStart_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStart.Click
        ApInfo()
    End Sub
    Private Sub ApInfo()
        'This string will contain the AP's SSID.
        Dim ApSSID As String = ""
        Dim client As New WlanClient()
        For Each wlanIface As WlanClient.WlanInterface In client.Interfaces
            Dim networks As Wlan.WlanAvailableNetwork() = wlanIface.GetAvailableNetworkList(0)
            For Each network As Wlan.WlanAvailableNetwork In networks
                'This check to see if the network is connected. If it is then it grabs the SSID.
                If network.flags = 3 Then
                    ApSSID = GetStringForSSID(network.dot11Ssid)
                    'Put the value in a textbox.
                    txtSSID.AppendText(ApSSID & vbCrLf)
                End If
            Next

            Dim wlanBssEntries As Wlan.WlanBssEntry() = wlanIface.GetNetworkBssList()
            'Now you can find the AP Mac then cross reference it to the SSID pulled earlier.
            For Each network2 As Wlan.WlanBssEntry In wlanBssEntries
                Dim macAddr As Byte() = network2.dot11Bssid
                Dim tMac As String = ""
                'If the SSID's match then output the result to a textbox.
                If GetStringForSSID(network2.dot11Ssid) = ApSSID Then
                    For i As Integer = 0 To macAddr.Length - 1
                        tMac += macAddr(i).ToString("x2").PadLeft(2, "0"c).ToUpper()
                    Next
                    txtApMAC.AppendText(tMac & vbCrLf)
                End If
            Next
        Next
    End Sub
'Used to convert the SSID to the proper format.
    Private Shared Function GetStringForSSID(ByVal ssid As Wlan.Dot11Ssid) As String
        Return Encoding.ASCII.GetString(ssid.SSID, 0, CInt(ssid.SSIDLength))
    End Function
End Class
The other way I found was using NetSH. You can grab the output of NetSH then reformat the output to get you what you want.
 Dim p = New Process()
p.StartInfo.FileName = "cmd.exe"
p.StartInfo.Arguments = ("/c netsh.exe wlan show interfaces | find " & Chr(34) & "BSSID" & Chr(34)) 'parameters.ToString()
p.StartInfo.UseShellExecute = False
p.StartInfo.CreateNoWindow = True
p.StartInfo.RedirectStandardOutput = True
p.Start()
p.WaitForExit(30000)
strCurrentAP = p.StandardOutput.ReadToEnd()
strCurrentAP = (strCurrentAP.Substring(29))