ActiveXperts Network Component SNMP MIB object
A management information base (MIB) is a database used to manage the devices in a communications network. The database is hierarchical (tree-structured) and entries are addressed through object identifiers (OID's).
A MIB should contain information on these commands and on the target objects (controllable entities or potential sources of status information) with a view to tuning the network transport to the current needs. Each type of object in a MIB database has a name, a syntax, and an encoding. The name is represented uniquely as an OID. An OID is an administratively assigned name. The administrative policies used for assigning names are discussed later in this memo.
Use Network Component's 'SnmpMibBrowser' object to load a MIB database into memory and iterate over all objects and view all properties.
Overview of all Network Component objects:
DnsServer & DnsRecord - Ftp & FtpFile - Http - Icmp - IPtoCountry - Msn - Ntp - Radius - Rsh - Scp - SFtp - Ssh - SnmpManager - SnmpTrapManager - SnmpMibBrowser - Tcp - Tftp - TraceRoute - Udp - Xen - Wake-on-LAN - Xen (Citrix)
SnmpTrapManager Sample code
Visual Basic .NET sample: Load a MIB file and browse through it
Imports AxNetwork
Module SnmpMib
Sub Main()
Dim objConstants As SocketConstants = New SocketConstants
Dim objSnmpMIB As SnmpMibBrowser = New SnmpMibBrowser
Dim strMibFile As String = ""
Dim bVerbose As Boolean = False
strMibFile = ReadInput("Enter MIB file", "c:\windows\system32\mib_ii.mib")
If (ReadInput("Verbose output (y/n) ?", "n") = "y") Then
bVerbose = True
Else
bVerbose = False
End If
Console.WriteLine("MIB File: " & strMibFile)
objSnmpMIB.LoadMibFile(strMibFile)
Console.WriteLine("LoadMibFile, result: " & objSnmpMIB.LastError.ToString() )
If (objSnmpMIB.LastError = 0) Then
ShowMIBTree(objSnmpMIB, objConstants, bVerbose)
End If
Console.WriteLine("Ready.")
System.Threading.Thread.Sleep(5000) ' Sleep for 5 seconds
End Sub
Private Sub ShowMIBTree(ByVal objSnmpMIB, ByVal objConstants, ByVal bVerbose)
Dim objSnmp As SnmpObject
Dim strDescription, strAccess, strStatus As String
Dim nDescription As Int32
' Start with "iso"
objSnmp = objSnmpMIB.Get("iso")
While (objSnmpMIB.LastError = 0)
Console.WriteLine(objSnmp.Path)
If (bVerbose = True) Then
strDescription = objSnmp.Description.ToString().ReplaceEx(vbCrLf,"[nl]").ReplaceEx(vbLf,"[nl]")
nDescription = strDescription.Length
If (nDescription > 40) Then
strDescription = strDescription.Substring(0, 40)
strDescription = strDescription & "..."
End If
If (objSnmp.Access = objConstants.asMIB_ACCESS_NOACCESS) Then
strAccess = "NOACCESS"
ElseIf (objSnmp.Access = objConstants.asMIB_ACCESS_NOTIFY) Then
strAccess = "NOTIFY"
ElseIf (objSnmp.Access = objConstants.asMIB_ACCESS_READONLY) Then
strAccess = "READONLY"
ElseIf (objSnmp.Access = objConstants.asMIB_ACCESS_WRITEONLY) Then
strAccess = "WRITEONLY"
ElseIf (objSnmp.Access = objConstants.asMIB_ACCESS_READWRITE) Then
strAccess = "READWRITE"
ElseIf (objSnmp.Access = objConstants.asMIB_ACCESS_READCREATE) Then
strAccess = "READCREATE"
Else
strAccess = "n/a"
End If
If (objSnmp.Status = objConstants.asMIB_STATUS_CURRENT) Then
strStatus = "CURRENT"
ElseIf (objSnmp.Status = objConstants.asMIB_STATUS_DEPRECATED) Then
strStatus = "DEPRECATED"
ElseIf (objSnmp.Status = objConstants.asMIB_STATUS_OBSOLETE) Then
strStatus = "OBSOLETE"
ElseIf (objSnmp.Status = objConstants.asMIB_STATUS_MANDATORY) Then
strStatus = "MANDATORY"
Else
strStatus = "n/a"
End If
Console.WriteLine(" OID: " & objSnmp.OID.ToString())
Console.WriteLine(" Description: " & strDescription)
Console.WriteLine(" Syntax: " & objSnmp.Syntax.ToString())
Console.WriteLine(" Access: " & strAccess)
Console.WriteLine(" Status: " & strStatus)
End If
objSnmp = objSnmpMIB.GetNext()
End While
End Sub
Private Function ReadInput(ByVal strTitle, ByVal strDefault) As String
Dim strInput As String = ""
Console.WriteLine(strTitle)
Console.Write(" > ")
strInput = Console.ReadLine()
If (strInput = "") Then
strInput = strDefault
End If
ReadInput = strInput
End Function
End Module
Visual C# .NET Sample: Load a MIB file and browse through it
using System;
using AxNetwork;
namespace SnmpMib
{
/// <summary>
/// Summary description for SnmpMibBrowser.
/// </summary>
class SnmpMib
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main(string[] args)
{
SnmpMibBrowser objSnmpMIB = new SnmpMibBrowser();
SocketConstants objConstants = new SocketConstants();
string strMibFile = "";
bool bVerbose = false;
strMibFile = ReadInput( "Enter MIB file", "c:\\windows\\system32\\mib_ii.mib" );
bVerbose = ReadInput( "Verbose output (y/n) ?", "n" ) == "y";
Console.WriteLine( "MIB File: " + strMibFile );
objSnmpMIB.LoadMibFile( strMibFile );
Console.WriteLine( "LoadMibFile, result: " + objSnmpMIB.LastError.ToString() );
if( objSnmpMIB.LastError == 0 )
{
ShowMIBTree( objSnmpMIB, objConstants, bVerbose );
}
Console.WriteLine( "Ready." );
System.Threading.Thread.Sleep(5000); // Sleep for 5 seconds
}
static private void ShowMIBTree(SnmpMibBrowser objSnmpMIB,SocketConstants objConstants,
bool bVerbose)
{
SnmpObject objSnmp;
string strDescription, strAccess, strStatus;
Int32 nDescription;
// Start with "iso"
objSnmp = ( SnmpObject ) objSnmpMIB.Get( "iso" );
while( objSnmpMIB.LastError == 0 )
{
Console.WriteLine( objSnmp.Path );
if( bVerbose )
{
strDescription=objSnmp.Description.ToString().ReplaceEx("\r\n","[nl]").ReplaceEx("\n","[nl]");
nDescription = strDescription.Length;
if( nDescription > 40 )
{
strDescription = strDescription.Substring( 0, 40 );
strDescription += "...";
}
if( objSnmp.Access == objConstants.asMIB_ACCESS_NOACCESS )
strAccess = "NOACCESS";
else if( objSnmp.Access == objConstants.asMIB_ACCESS_NOTIFY )
strAccess = "NOTIFY";
else if( objSnmp.Access == objConstants.asMIB_ACCESS_READONLY )
strAccess = "READONLY";
else if( objSnmp.Access == objConstants.asMIB_ACCESS_WRITEONLY )
strAccess = "WRITEONLY";
else if( objSnmp.Access == objConstants.asMIB_ACCESS_READWRITE )
strAccess = "READWRITE";
else if( objSnmp.Access == objConstants.asMIB_ACCESS_READCREATE )
strAccess = "READCREATE";
else
strAccess = "n/a";
if( objSnmp.Status == objConstants.asMIB_STATUS_CURRENT )
strStatus = "CURRENT";
else if( objSnmp.Status == objConstants.asMIB_STATUS_DEPRECATED )
strStatus = "DEPRECATED";
else if( objSnmp.Status == objConstants.asMIB_STATUS_OBSOLETE )
strStatus = "OBSOLETE";
else if( objSnmp.Status == objConstants.asMIB_STATUS_MANDATORY )
strStatus = "MANDATORY";
else
strStatus = "n/a";
Console.WriteLine( " OID: " + objSnmp.OID.ToString() );
Console.WriteLine( " Description: " + strDescription );
Console.WriteLine( " Syntax: " + objSnmp.Syntax.ToString() );
Console.WriteLine( " Access: " + strAccess );
Console.WriteLine( " Status: " + strStatus );
}
objSnmp = ( SnmpObject ) objSnmpMIB.GetNext();
}
}
static private string ReadInput( string strTitle, string strDefault )
{
string strInput = "";
Console.WriteLine( strTitle );
Console.Write(" > ");
strInput = Console.ReadLine();
if( strInput == "" )
strInput = strDefault;
return strInput;
}
}
}
You can download the full samples here.
