Shortcut Menu

Skip

Main Navigation

Choose your language


ActiveXperts Network Monitor
Monitor servers, workstations, devices and applications in your network

Quicklinks


SNMP Scripts

Retrieving SNMP MIB-II Interface Table Information
Retrieving SNMP MIB-II System Group Information
Retrieving SNMP MIB-II TCP and UDP Connections and Listening Ports

Retrieving SNMP MIB-II Interface Table Information


Retrieves and displays SNMP MIB-II (RFC 1213) Interface Table information from an SNMP managed node using the WMI SNMP Provider.
strTargetSnmpDevice = "192.168.0.1"
 
Set objWmiLocator = CreateObject("WbemScripting.SWbemLocator")
Set objWmiServices = objWmiLocator.ConnectServer("", "root\snmp\localhost")
 
Set objWmiNamedValueSet = CreateObject("WbemScripting.SWbemNamedValueSet")
objWmiNamedValueSet.Add "AgentAddress", strTargetSnmpDevice
objWmiNamedValueSet.Add "AgentReadCommunityName", "public"
 
Set colIfTable = objWmiServices.InstancesOf("SNMP_RFC1213_MIB_ifTable", , _
    objWmiNamedValueSet)
 
For Each objInterface In colIfTable
    WScript.Echo "ifIndex [Key]:        " & objInterface.ifIndex  & vbCrLf & _
        "   ifAdminStatus:     " & objInterface.ifAdminStatus     & vbCrLf & _
        "   ifDescr:           " & objInterface.ifDescr           & vbCrLf & _
        "   ifInDiscards:      " & objInterface.ifInDiscards      & vbCrLf & _
        "   ifInErrors:        " & objInterface.ifInErrors        & vbCrLf & _
        "   ifInNUcastPkts:    " & objInterface.ifInNUcastPkts    & vbCrLf & _
        "   ifInOctets:        " & objInterface.ifInOctets        & vbCrLf & _
        "   ifInUcastPkts:     " & objInterface.ifInUcastPkts     & vbCrLf & _
        "   ifInUnknownProtos: " & objInterface.ifInUnknownProtos & vbCrLf & _
        "   ifLastChange:      " & objInterface.ifLastChange      & vbCrLf & _
        "   ifMtu:             " & objInterface.ifMtu             & vbCrLf & _
        "   ifOperStatus:      " & objInterface.ifOperStatus      & vbCrLf & _
        "   ifOutDiscards:     " & objInterface.ifOutDiscards     & vbCrLf & _
        "   ifOutErrors:       " & objInterface.ifOutErrors       & vbCrLf & _
        "   ifOutNUcastPkts:   " & objInterface.ifOutNUcastPkts   & vbCrLf & _
        "   ifOutOctets:       " & objInterface.ifOutOctets       & vbCrLf & _
        "   ifOutQLen:         " & objInterface.ifOutQLen         & vbCrLf & _
        "   ifOutUcastPkts:    " & objInterface.ifOutUcastPkts    & vbCrLf & _
        "   ifPhysAddress:     " & objInterface.ifPhysAddress     & vbCrLf & _
        "   ifSpecific:        " & objInterface.ifSpecific        & vbCrLf & _
        "   ifSpeed:           " & objInterface.ifSpeed           & vbCrLf & _
        "   ifType:            " & objInterface.ifType            & vbCrLf
Next

Retrieving SNMP MIB-II System Group Information


Retrieves and displays SNMP MIB-II (RFC 1213) System Group information from an SNMP managed node using the WMI SNMP Provider.
strTargetSnmpDevice = "192.168.0.1"
 
Set objWmiLocator = CreateObject("WbemScripting.SWbemLocator")
Set objWmiServices = objWmiLocator.ConnectServer("", "root\snmp\localhost")
 
Set objWmiNamedValueSet = CreateObject("WbemScripting.SWbemNamedValueSet")
objWmiNamedValueSet.Add "AgentAddress", strTargetSnmpDevice
objWmiNamedValueSet.Add "AgentReadCommunityName", "public"
 
Set colSystem = objWmiServices.InstancesOf("SNMP_RFC1213_MIB_system", , _
    objWmiNamedValueSet)
 
For Each objSystem In colSystem
    WScript.Echo "sysContact:  " & objSystem.sysContact  & vbCrLf & _
                 "sysDescr:    " & objSystem.sysDescr    & vbCrLf & _
                 "sysLocation: " & objSystem.sysLocation & vbCrLf & _
                 "sysName:     " & objSystem.sysName     & vbCrLf & _
                 "sysObjectID: " & objSystem.sysObjectID & vbCrLf & _
                 "sysServices: " & objSystem.sysServices & vbCrLf & _
                 "sysUpTime:   " & objSystem.sysUpTime
Next

Retrieving SNMP MIB-II TCP and UDP Connections and Listening Ports


Retrieves and displays SNMP MIB-II (RFC 1213) TCP (and UDP) connections and listening ports from an SNMP managed node using the WMI SNMP Provider. Equivalent to running netstat -a -n (which displays all connections and listening ports in numerical form).
strTargetSnmpDevice = "192.168.0.1"
 
Set objWmiLocator = CreateObject("WbemScripting.SWbemLocator")
Set objWmiServices = objWmiLocator.ConnectServer("", "root\snmp\localhost")
 
Set objWmiNamedValueSet = CreateObject("WbemScripting.SWbemNamedValueSet")
objWmiNamedValueSet.Add "AgentAddress", strTargetSnmpDevice
objWmiNamedValueSet.Add "AgentReadCommunityName", "public"
 
Set colTcpConnTable = _
    objWmiServices.InstancesOf("SNMP_RFC1213_MIB_tcpConnTable", , _
        objWmiNamedValueSet)
 
Set colUdpTable = _
    objWmiServices.InstancesOf("SNMP_RFC1213_MIB_udpTable", , _
        objWmiNamedValueSet)
 
 
WScript.Echo "TCP Connections and Listening Ports" & vbCrLf & _
    "-----------------------------------"
 
For Each objTcpConn In colTcpConnTable
    WScript.Echo objTcpConn.tcpConnLocalAddress & ":"    & _
                 objTcpConn.tcpConnLocalPort    & " => " & _
                 objTcpConn.tcpConnRemAddress   & ":"    & _
                 objTcpConn.tcpConnRemPort      & " "    & _
                 "[State: " & objTcpConn.tcpConnState & "]"
Next
 
WScript.Echo vbCrLf & "UDP Ports" & vbCrLf & "---------"
 
For Each objUdp In colUdpTable
    WScript.Echo objUdp.udpLocalAddress & ":" & objUdp.UdpLocalPort
Next