#200416 - 2010-10-29 01:12 PM
convert vbs to kix
|
roundup
Fresh Scripter
Registered: 2010-10-29
Posts: 11
Loc: Denmark
|
I have found a vbs/wmi script that works, it find the bssid of the acesspoint the client is currently connected to. I want to use this in kix, my problem is to isolate the mac value the bssid returns to further use in kix! I have made a call to this vbs script from kix but i can not return the bssid value that is found here for use in kix. I want to use it to locate the client an map the printer nearest, with use of a case command in kix. But after calling this vbs script the bssid/mac get lost?
can anyone please help med with this problem, or maybe convert the vbs script to kix!?
Kind regards roundup
' edit strComputer, save to a dir, open up cmd shell, and type: cscript GETBSSID.vbs
filename = "GETBSSID.vbs"
version = "Version 1.0"
description = "Get BSSID of local XP machine's Wi-Fi card via WMI."
' cmd: GETBSSID.vbs 1 (where 1 here is the wifi_cardnr )
strComputer = "."
set objSWbemServices = GetObject("winmgmts:\\"& strComputer & "\root\wmi")
' wscript.echo description & vbcrlf & version & vbcrlf
' find adapters by querying for active signal
set colInstances = objSwbemServices.ExecQuery _
("SELECT * FROM MSNdis_80211_ReceivedSignalStrength WHERE Active = True")
if wscript.Arguments.Count = 0 Then ' spit out usage and cards if no args
wscript.echo "Skriv: cscript " & filename & " [kortnr]"
card_no=1
for each objInstance in colInstances ' more than one instance per card may show up, btw
wscript.echo card_no & " = " & objInstance.InstanceName
card_no=card_no +1
next
wscript.quit
end If
' numberify the arg and set our adapter, matching command arg with an instancename
card_no=abs(wscript.Arguments(0))
x=1
for each objInstance in colInstances
if x = card_no then
wifiAdapter = objInstance.InstanceName
x = x + 1
end if
next
' wscript.echo "Using " & wifiAdapter & vbcrlf
last_signal = 0 ' we need to initialize this, but I'm not sure if -90 would be a better val to start with
' get bssid
bssid = ""
set colInstances = objSwbemServices.ExecQuery ("SELECT * FROM MSNdis_80211_BaseServiceSetIdentifier WHERE Active = True AND InstanceName ='" & wifiAdapter & "'")
for each objInstance in colInstances
macbyte = 0
' convert decimals to hex. pad zeros & slip in colons where needed
for each decval in objInstance.Ndis80211MacAddress
if decval<17 then
bssid = bssid & "0"
end if
bssid = bssid & Hex(decval)
if macbyte < 5 then
bssid = bssid & ":"
macbyte = macbyte + 1
end if
next
next
' get ssid
' ssid = ""
' set colInstances = objSwbemServices.ExecQuery _
' ("SELECT * FROM MSNdis_80211_ServiceSetIdentifier WHERE Active = True AND InstanceName ='" & wifiAdapter & "'")
' for each objInstance in colInstances
' convert decimals to chars and avoid non-alphanumerics
' for each decval in objInstance.Ndis80211SsId
' if (decval > 31 AND decval < 127) then
' ssid = ssid & Chr(decval)
' end if
' next
' next
' this could be tricky, as I've read signal strength is reported in different ways per card. YMMV.
set colInstances = objSwbemServices.ExecQuery _
("SELECT * FROM MSNdis_80211_ReceivedSignalStrength WHERE Active = True AND InstanceName ='" & wifiAdapter & "'")
for each objInstance in colInstances
sigraw = objInstance.Ndis80211ReceivedSignalStrength ' raw number for later comparison
signal = sigraw & "dB" ' make it a string that says dB
next
last_signal = sigraw
' Wscript.echo "BSSID: " & bssid & " SSID: " & ssid & " RSSI: " & signal
Wscript.echo "BSSID: " & bssid
Edited by Mart (2010-10-29 01:47 PM) Edit Reason: Please use code tags when posting code.
|
|
Top
|
|
|
|
#200450 - 2010-11-01 02:38 PM
Re: convert vbs to kix
[Re: Allen]
|
roundup
Fresh Scripter
Registered: 2010-10-29
Posts: 11
Loc: Denmark
|
Hi Allan
Many thanks for your reply I have read and tried with the info you have written but it does still not work!?
$ Output = wshpipe ("\\servername\netlogon\GETBSSID.vbs 1) * 1 is for the computer's internal wifi cardnr.
How can I return the MAC value from the called vbs script in shell?
When run it from a commandprompt it pops up with the BSSID in a window ? Wscript.echo "BSSID:" & BSSID
Sincerely, roundup
|
|
Top
|
|
|
|
#200452 - 2010-11-01 04:23 PM
Re: convert vbs to kix
[Re: roundup]
|
Shanee
Fresh Scripter
Registered: 2006-10-13
Posts: 39
Loc: Tulsa, OK
|
Here is a stripped down version of your vbs script, converted into a kix function. Just copy the function to your existing kix script, and you can call the function at any time using the card number you want, and the computer you want. I didn't write in any error checking, so you may want to test it out a bit beforehand. But should get you started.
$bssid = GetBSSID(1,@Wksta)
$null = MessageBox($bssid,"BSSID",0)
FUNCTION GetBSSID($device, optional $machine)
$strComputer = IIF (VarType($machine)<2, @Wksta, $Machine)
$objSWbemServices = GetObject("winmgmts:\\"+ $strComputer + "\root\wmi")
$colInstances = $objSwbemServices.ExecQuery("SELECT * FROM MSNdis_80211_ReceivedSignalStrength WHERE Active=True")
$card_no=$device
$x=1
for each $objInstance in $colInstances
if $x = $card_no
$wifiAdapter = $objInstance.InstanceName
$x = $x + 1
endif
next
$last_signal = 0
$bssid = ""
$colInstances = $objSwbemServices.ExecQuery('SELECT * FROM MSNdis_80211_BaseServiceSetIdentifier WHERE Active = True AND InstanceName ="'+$wifiAdapter+'"')
for each $objInstance in $colInstances
$macbyte = 0
for each $decval in $objInstance.Ndis80211MacAddress
if $decval<17
$bssid = $bssid + "0"
endif
$bssid = $bssid + DecToHex($decval)
if $macbyte < 5
$bssid = $bssid + ":"
$macbyte = $macbyte + 1
endif
next
next
$colInstances = $objSwbemServices.ExecQuery ("SELECT * FROM MSNdis_80211_ReceivedSignalStrength WHERE Active = True AND InstanceName ='" + $wifiAdapter + "'")
for each $objInstance in $colInstances
$sigraw = $objInstance.Ndis80211ReceivedSignalStrength
$signal = $sigraw + "dB"
next
$last_signal = $sigraw
$GetBSSID = $bssid
ENDFUNCTION
|
|
Top
|
|
|
|
#200453 - 2010-11-01 04:27 PM
Re: convert vbs to kix
[Re: Shanee]
|
Shanee
Fresh Scripter
Registered: 2006-10-13
Posts: 39
Loc: Tulsa, OK
|
I changed it a bit more, now if you dont specify a card number it will return a message with a list of cards.
Some examples ways to call the function and have the results pop up in a message...
$bssid = GetBSSID() $null = MessageBox($bssid,"BSSID",0)
$bssid = GetBSSID(1) $null = MessageBox($bssid,"BSSID",0)
$bssid = GetBSSID(1,@WkSta) $null = MessageBox($bssid,"BSSID",0)
FUNCTION GetBSSID(optional $device, optional $machine)
$strComputer = IIF (VarType($machine)<2, @Wksta, $Machine)
$objSWbemServices = GetObject("winmgmts:\\"+ $strComputer + "\root\wmi")
$colInstances = $objSwbemServices.ExecQuery("SELECT * FROM MSNdis_80211_ReceivedSignalStrength WHERE Active=True")
if $device<1
$card_no=1
$cards = "Please specify one of these devices to obtain it's BSSID :"
for each $objInstance in $colInstances
$cards = $cards+@CRLF+"Card "+$card_no+" = "+$objInstance.InstanceName
$card_no=$card_no +1
next
$GetBSSID = $cards
Return
endIf
$card_no=$device
$x=1
for each $objInstance in $colInstances
if $x = $card_no
$wifiAdapter = $objInstance.InstanceName
$x = $x + 1
endif
next
$last_signal = 0
$bssid = ""
$colInstances = $objSwbemServices.ExecQuery('SELECT * FROM MSNdis_80211_BaseServiceSetIdentifier WHERE Active = True AND InstanceName ="'+$wifiAdapter+'"')
for each $objInstance in $colInstances
$macbyte = 0
for each $decval in $objInstance.Ndis80211MacAddress
if $decval<17
$bssid = $bssid + "0"
endif
$bssid = $bssid + DecToHex($decval)
if $macbyte < 5
$bssid = $bssid + ":"
$macbyte = $macbyte + 1
endif
next
next
$colInstances = $objSwbemServices.ExecQuery ("SELECT * FROM MSNdis_80211_ReceivedSignalStrength WHERE Active = True AND InstanceName ='" + $wifiAdapter + "'")
for each $objInstance in $colInstances
$sigraw = $objInstance.Ndis80211ReceivedSignalStrength
$signal = $sigraw + "dB"
next
$last_signal = $sigraw
$GetBSSID = $bssid
ENDFUNCTION
|
|
Top
|
|
|
|
#200465 - 2010-11-02 10:44 AM
Re: convert vbs to kix
[Re: Shanee]
|
roundup
Fresh Scripter
Registered: 2010-10-29
Posts: 11
Loc: Denmark
|
Hello Shanee
Thanks for your great help, it works perfectly and just what I was looking for. 
Sincerely, Jesper Lauenborg
|
|
Top
|
|
|
|
Moderator: Glenn Barnas, NTDOC, Arend_, Jochen, Radimus, Allen, ShaneEP, Ruud van Velsen, Mart
|
0 registered
and 837 anonymous users online.
|
|
|