Contact Info

Crumbtrail » Network Component » How to Use Network Component » SNMP MIB » VBScript

How to use SNMP MIB Browser in VBScript

Network Component provides an easy-to-use development interface to a variety of IP protocols. By using Network Component, you can very easily create or enhance applications with network features.

Network Component features the following: DNS, FTP, HTTP, HTTPs, ICMP Ping, IP-to-Country, MSN, NTP, RSH, SCP, SFTP, SNMP v1/v2c (Get, GetNext, Set), SNMP Traps, SNMP MIB, SSH, TCP, Telnet, TFTP, UDP, Telnet, Wake-On-LAN and more.

Network Component can be well integrated into any development platform that supports ActiveX objects.

SNMP can be well integrated into ASP .NET (Visual Basic) environments.

This document describes how Network Component's SNMP objects can be integrated into ASP .NET (Visual Basic) projects.

Network Component is compliant with SNMP v1 and SNMP v2c. Different SNMP data types are supported, including:

The following operations are supported:

Step 1: Download and install the Network Component

Download Network Component from the ActiveXperts Download Site and start the installation. The installation guides you through the installation process.

Step 2: Create a new script

Create a new script using your favorite editor. You can simply use notepad. However, a VBScript editor is recommended, so you can browse through objects, objects properties and object functions.

You're now able to write a more advanced script to communicate using the Network Component.

Step 3: Create the Network Component object in VBScript

Create a new VBScript file called DEMO.VBS. It is recommended to insert the following line on top of your code:

Option Explicit

This statement requires that all variable names be defined (with the Dim statement), to avoid simple typos that can cause incredible headaches and long debugging sessions for something that should have never happened.

Now, declare the Network Component object(s):

Dim objSnmpMibBrowser

Create the Network Component object(s) like this:

Set objSnmpMibBrowser      = CreateObject( "AxNetwork.SnmpMibBrowser" )

Now, add the following lines to the file to have your first Network Component VBScript program:

WScript.Echo "Version: " & objSnmpMibBrowser.Version
WScript.Echo "License Status: " & objSnmpMibBrowser.LicenseStatus

Appendix: Full source code

' ********************************************************************
' ActiveXperts Network Component sample - SNMP MIB Browser
'   Load a MIB file, and show all properties
' Written by ActiveXperts Software 
' ********************************************************************

Option Explicit

Dim objSnmpMib, objConstants, fso
Dim strMibFile, strHost

Set objSnmpMib = CreateObject( "AxNetwork.SnmpMibBrowser" )
Set objConstants = CreateObject( "AxNetwork.NwConstants" )

' A license key is required to unlock this component after the trial period has expired.
' Call 'Activate' with a valid license key as its first parameter. Second parameter determines whether to save the license key permanently 
' to the registry (True, so you need to call Activate only once), or not to store the key permanently (False, so you need to call Activate
' every time the component is created). For details, see manual, chapter "Product Activation".
' objSnmpManager.Activate "XXXXX-XXXXX-XXXXX", False

' Component info
Wscript.Echo "ActiveXpert Network Component " & objSnmpManager.Version
Wscript.Echo "Build: " & objSnmpManager.Build & vbCrLf & "Module: " & objSnmpManager.Module
Wscript.Echo "License Status: " & objSnmpManager.LicenseStatus & vbCrLf & "License Key: " & objSnmpManager.LicenseKey & vbCrLf

' Set Logfile
Set fso = CreateObject( "Scripting.FileSystemObject" )
objSnmpManager.LogFile = fso.GetSpecialFolder(2) & "\SnmpManager.log"
WScript.Echo "Log file: " & objSnmpManager.LogFile & vbCrLf

strMibFile = ReadInput( "Enter MIB file (leave blank for a Windows System MIB file)", "c:\windows\system32\mib_ii.mib", False )

WScript.Echo "MIB File: " & strMibFile

WScript.Echo( "LoadMibFile, result: " & objSnmpMib.LastError & " (" & objSnmpMib.GetErrorDescription( objSnmpMib.LastError ) & ")")
If( objSnmpMib.LastError = 0 ) Then
   ShowMIBTree objSnmpMib, objConstants 
End If

WScript.Echo "Ready."

Sub ShowMIBTree( ByVal objSnmpMIB, ByVal objConstants )

  Dim objSnmp, strDescription, nDescription, strAccess, strStatus

  ' Start with "iso"
  Set objSnmp = objSnmpMIB.Get("iso")

  While (objSnmpMIB.LastError = 0)

    strDescription = ReplaceEx( objSnmp.Description, vbCrLf, " [nl] ")
    strDescription = ReplaceEx( strDescription, vbLf, " [nl] ")
    nDescription = Len( strDescription )
    If (nDescription > 40) Then
      strDescription = Left( strDescription, 40 )
      strDescription = strDescription & "..."
    End If
    If (objSnmp.Access = objConstants.nwMIB_ACCESS_NOACCESS) Then
      strAccess = "NOACCESS"
    ElseIf (objSnmp.Access = objConstants.nwMIB_ACCESS_NOTIFY) Then
      strAccess = "NOTIFY"
    ElseIf (objSnmp.Access = objConstants.nwMIB_ACCESS_READONLY) Then
      strAccess = "READONLY"
    ElseIf (objSnmp.Access = objConstants.nwMIB_ACCESS_WRITEONLY) Then
      strAccess = "WRITEONLY"
    ElseIf (objSnmp.Access = objConstants.nwMIB_ACCESS_READWRITE) Then
      strAccess = "READWRITE"
    ElseIf (objSnmp.Access = objConstants.nwMIB_ACCESS_READCREATE) Then
      strAccess = "READCREATE"
      strAccess = "n/a"
    End If

    If (objSnmp.Status = objConstants.nwMIB_STATUS_CURRENT) Then
      strStatus = "CURRENT"
    ElseIf (objSnmp.Status = objConstants.nwMIB_STATUS_DEPRECATED) Then
      strStatus = "DEPRECATED"
    ElseIf (objSnmp.Status = objConstants.nwMIB_STATUS_OBSOLETE) Then
      strStatus = "OBSOLETE"
    ElseIf (objSnmp.Status = objConstants.nwMIB_STATUS_MANDATORY) Then
      strStatus = "MANDATORY"
      strStatus = "n/a"
    End If

    WScript.Echo "OID: " & objSnmp.OID
    WScript.Echo "  Name: " & objSnmp.OIDName        
    WScript.Echo "  Description: " & strDescription
    WScript.Echo "  Syntax: " & objSnmp.Syntax
    WScript.Echo "  Access: " & strAccess
    WScript.Echo "  Status: " & strStatus

    Set objSnmp = objSnmpMIB.GetNext()
End Sub

' ***************************************************************************
' Function ReadInput
' ***************************************************************************
Function ReadInput( ByVal strTitle, ByVal strDefault, ByVal bAllowEmpty )

   Dim strInput, strReturn
      strInput = inputbox( strTitle, "Enter value", strDefault )
      If ( strInput <> "" ) Then
         strReturn = strInput
      End If
   Loop until strReturn <> "" Or bAllowEmpty
   ReadInput = strReturn
End Function

You can download the complete sample on our FTP site There are many other working Network Component scripts on our site and shipped with the product.