const vlanPortIslVlansAllowed = " .1.3.6.1.4.1.9.5.1.9.3.1.5.1.1 " const SNMPGETCMD2 = "f:\usr\bin\snmpget.exe -Ov -v 2c -c " '************************************************************************ 'FUNCTION: * ' enum_AllowedVLAN(strAgent) * 'Purpose: * ' enumerate the vlans configured on the switch. * ' * 'Inputs: * ' strAgent: management IP address of the switch * ' * 'Returns: * ' Array with each element containing a vlan number * ' * 'Calls: * ' SNMPGETCMD2 - constant defining the path to an external * ' program and options used to perform an snmp get operation. * ' fmtBinary - function to left pad a binary number with zeros * ' ToBinary - function to convert an integer to a binary string * ' * 'Comments: * ' CISCO-STACK-MIB is cisco specific. * ' Reference Cisco SNMP Object Navigator viewed at * ' http://tools.cisco.com/Support/SNMP/do/BrowseOID.do? * ' objectInput=vlanPortIslVlansAllowed&translate=Translate& * ' submitValue=SUBMIT&submitClicked=true * ' on 16/11/2006 * '************************************************************************ function enum_AllowedVLAN(strAgent) dim WshShell, oExec dim re 'as regexp dim matches dim match, submatch dim tempstr, stroutput, index, vlans Set WshShell = CreateObject("WScript.Shell") Set oExec = WshShell.Exec(SNMPGETCMD2 & SNMPREAD & " " & _ strAgent & " " & vlanPortIslVlansAllowed) Do while Not oExec.StdOut.AtEndOfStream stroutput = oExec.StdOut.readall Loop Do While oExec.Status <> 1 WScript.Sleep 100 Loop tempstr = "" set re = new regexp re.global = True re.multiline = True 'Pattern to capture the hex digits representing the allowed vlans. re.pattern = "[0-9a-fA-F]{2}" vlans = "" if instr(1,stroutput, "Hex-STRING:") > 0 then set matches = re.execute(stroutput) for each match in matches tempstr = tempstr & fmtBinary(ToBinary(cint("&H" & match)), 8) next tempstr = strreverse(tempstr) index = 1 do index = instr(index, tempstr, "1") if index <> 0 then vlans = vlans & " " & index - 1 index = index + 1 end if loop until index = 0 end if enum_AllowedVLAN = split(trim(vlans)) end function '************************************************************************ 'FUNCTION: * ' fmtBinary(strNumber, intLength) * 'PURPOSE: * ' function to left pad a binary number with zeros * ' * 'INPUTS: * ' strNumber: binary number to left pad with zeros * ' intLength: The desired bit length of the binary number * ' * 'RETURNS: * ' string containing the binary representation of the input. * ' * 'CALLS: * ' Nothing * ' * 'COMMENTS: * '************************************************************************ function fmtBinary(strNumber, intLength) fmtBinary = string(intLength - len(strNumber), "0") & strNumber end function '************************************************************************ 'FUNCTION: * ' ToBinary(intNumber) * ' * 'PURPOSE: * ' convert an integer number to binary. * ' * 'Inputs: * ' intNumber: Number to convert to binary * ' * 'Returns: * ' string containing the binary representation of the input. * ' * 'Calls: * ' Nothing * ' * 'Comments: * ' note the use of \ (integer division operator) rather than / * '************************************************************************ function ToBinary(intNumber) if intNumber > 0 then ToBinary = ToBinary(intNumber\2) & intNumber mod 2 end if end function