Use SnmpSource component to GET bulk snmp. Snmp version 1 doesn't support bulk request.
To use this code sample, add a reference to the following
assemblies:
SnmpSource.dll
Then import the following namespaces at the top of your code file with
using
(for C#) or Imports
(for
VB) keywords:
SnmpSource
[C#]
//create snmp session
SnmpSession s1 = new SnmpSession();
//create snmp pdu
SnmpPdu pdu = new SnmpPdu();
//Specify the Pdu type
pdu.PduType = EnumPduType.GetBulkPdu;
//Set the community string
pdu.Community = "public";
pdu.Version = SnmpVersion.Version2;
// set non-repeaters
pdu.BulkNonRepeaters = 1;
// set max-repetitions
pdu.BulkMaxRepetitions = 2;
//creat response pdu
SnmpPdu response = null;
// Try to retrieve bulk snmp record
try
{
// Add snmp variable
SnmpVariable var = SnmpVariable.CreateSnmpVariable("1.3.6.1.2.1.1.5.0");
pdu.AddRequestVariables(var);
var = SnmpVariable.CreateSnmpVariable("1.3.6.1.2.1.2.2.1.1.0");
pdu.AddRequestVariables(var);
var = SnmpVariable.CreateSnmpVariable("1.3.6.1.2.1.2.2.1.2.0");
pdu.AddRequestVariables(var);
// Asynchronized request snmp SyncRequest(hostip, port, pdu)
response = s1.SyncRequest("127.0.0.1", 161, pdu);
}
catch (Exception ex)
{
System.Console.Error.WriteLine("Sending PDU: " + ex.Message);
System.Environment.Exit(1);
}
// Display the result
try
{
if(response.ErrorStatus == 0)
{
for (int k=0; k< response.InnerVariables.Count; k++)
{
System.Console.WriteLine("Response oid: " + response.InnerVariables[k].OID);
System.Console.WriteLine("Response value: " + response.InnerVariables[k].Data.ToString());
System.Console.WriteLine("");
}
}
else
{
System.Console.WriteLine("Response error code: " + response.ErrorStatus);
}
}
catch (Exception ex)
{
System.Console.WriteLine("Error in output: " + ex.Message);
}
[Vb]
'create snmp session
Dim
s1 As New SnmpSession
'create snmp pdu
Dim pdu As New SnmpPdu
'Specify the Pdu type
pdu.PduType = EnumPduType.GetBulkPdu
'Set the community string
pdu.Community = "public"
pdu.Version = SnmpVersion.Version2
' set non-repeaters
pdu.BulkNonRepeaters = 1
' set max-repetitions
pdu.BulkMaxRepetitions = 2
'creat response pdu
Dim response As SnmpPdu = Nothing
' Try to retrieve snmp record
Try
' Add snmp variable
Dim variable1 As SnmpVariable = SnmpVariable.CreateSnmpVariable("1.3.6.1.2.1.1.5.0")
pdu.AddRequestVariables(variable1)
variable1 = SnmpVariable.CreateSnmpVariable("1.3.6.1.2.1.2.2.1.1.0")
pdu.AddRequestVariables(variable1)
variable1 = SnmpVariable.CreateSnmpVariable("1.3.6.1.2.1.2.2.1.2.0")
pdu.AddRequestVariables(variable1)
response = s1.SyncRequest("127.0.0.1", 161, pdu)
Catch exception1 As Exception
Console.Error.WriteLine(("Sending PDU: " & exception1.Message))
Environment.Exit(1)
End Try
' Display the result
Try
If (response.ErrorStatus = SnmpErrorStatus.noError) Then
Dim i As Integer
For i = 0 To response.InnerVariables.Count - 1
Console.WriteLine(("Response oid: " & response.InnerVariables.Item(i).OID))
Console.WriteLine(("Response value: " & response.InnerVariables.Item(i).Data.ToString))
Console.WriteLine("")
Next i
Else
Console.WriteLine(("Response error code: " & response.ErrorStatus))
End If
Catch exception2 As Exception
Console.WriteLine(("Error in output: " & exception2.Message))
Return
End Try
The syntax to use the included command line example.
Syntax: snmpbulk [Options] NonRepeaters MaxRepetions host oid [oid] ...
Options:
/version:v1|v2 or /v:v1|v2 Specify the version number. /port:portnumber or /p:portnumber Specify the port number. /timeout:ms or /t:ms Time out in milliseconds. /debug or /d Turn on the debug setting. /community:community or /c:community Set community. /? or /help Display this usage message.
Example: snmpbulk /d /v:v2 /c:public 1 2 127.0.0.1 1.3.6.1.2.1.1.5.0 1.3.6.1.2.1.2.2.1.1.0 1.3.6.1.2.1.2.2.1.2.0
Copyright