Jump to content
Sign in to follow this  
jazzyjeff

Obtain WAP MAC Address problem

Recommended Posts

jazzyjeff

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

Share this post


Link to post
Share on other sites
PsaltyDS

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

Share this post


Link to post
Share on other sites
jazzyjeff

Sorry, I probably didn't explain this very well. I don't even get a message box. It's like it's not reading the WMI code properly.

Share this post


Link to post
Share on other sites
PsaltyDS

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

Share this post


Link to post
Share on other sites
jazzyjeff

I am running this from Scite, and there are no errors in the console. The script just exits.

I'm not familiar with creating COM Error Handlers, so now seems the time to learn!

Share this post


Link to post
Share on other sites
jazzyjeff

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)

Share this post


Link to post
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
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.