Jump to content

Obtain WAP MAC Address problem


Recommended Posts

Hello,

I am trying to obtain the MAC Address of the Wireless Access Point that I am trying to connect to. With some research I have found that this WMI Class, MSNdis_80211_BaseServiceSetIdentifier, should provide the solution for me. Unfortunately, I cannot get the information to appear in a message, or quite simply the MAC Address is not being read by the WMI script.

Has anyone done this before, or have any ideas how to fix this? I'd appreciate any help.

My script is below.

Thanks,

Jeff

$wbemFlagReturnImmediately = 0x10
    $wbemFlagForwardOnly = 0x20
    $colItems = ""
    $strComputer = "localhost"

    $Output=""
    $Output = $Output & "Computer: " & $strComputer  & @CRLF
    $Output = $Output & "==========================================" & @CRLF
    $objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\")
    $colItems = $objWMIService.ExecQuery("SELECT * FROM MSNdis_80211_BaseServiceSetIdentifier", "WQL", _
                                              $wbemFlagReturnImmediately + $wbemFlagForwardOnly)

    If IsObj($colItems) Then
        For $objItem In $colItems
          $strAPMac = $objItem.Ndis80211MacAddress
          $Output = "AP MAC: " & $strAPMac
            Msgbox(1,"WMI Output",$Output)
        Next
    Else
        Msgbox(0,"WMI Output","No WMI Objects Found for class: " & "Win32_NetworkAdapterConfiguration" )
    Endif
#cs
Func WMIDateStringToDate($dtmDate)

    Return (StringMid($dtmDate, 5, 2) & "/" & _
    StringMid($dtmDate, 7, 2) & "/" & StringLeft($dtmDate, 4) _
    & " " & StringMid($dtmDate, 9, 2) & ":" & StringMid($dtmDate, 11, 2) & ":" & StringMid($dtmDate,13, 2))
EndFunc
#ce
Link to comment
Share on other sites

You didn't say which MsgBox() you got. Is it finding an instance of MSNdis_80211_BaseServiceSetIdentifier or not?

If so, see what variable type you are getting back for that property:

For $objItem In $colItems
        $strAPMac = $objItem.Ndis80211MacAddress
        $Output = "Type = " & VarGetType($strAPMac) & @CRLF & "AP MAC: " & $strAPMac
        MsgBox(1, "WMI Output", $Output)
    Next

You should probably add a basic COM Error handler too. See help file.

;)

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

Add the afore-mentioned COM Error handler.

Your "If IsObj()" should return one MsgBox() or the other unless it is crashing or blocking. Does the script just hang or exit?

Are you running it from SciTE so you can see any errors in the console pane?

;)

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

I found a solution to my problem. It's not really how I wanted to do this, but it works.

Maybe it'll help someone else out.

RunWait(@ComSpec & " /c " & "netsh wlan show interfaces > C:\Windows\Temp\BSSID.txt","",@SW_HIDE)
$File = FileOpen("C:\Windows\Temp\BSSID.txt")
$Read = FileReadLine($File, 10)
$MAC = StringRight($Read,17)
FileDelete("C:\Windows\Temp\BSSID.txt")
MsgBox(0,"WAP MAC Address","The MAC Address of the Wireless Access Point you are connected to is: " & @CR & @CR & $MAC)
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...