SnmpSource Help

SnmpSession Class

SnmpSession sends snmp request synchronizely or asynchronizely.

For a list of all members of this type, see SnmpSession Members.

System.Object
   SnmpSource.SnmpSession

public class SnmpSession

Thread Safety

Public static (Shared in Visual Basic) members of this type are safe for multithreaded operations. Instance members are not guaranteed to be thread-safe.

Example

//create snmp session
SnmpSession s1 = new SnmpSession(); 
//create snmp pdu
SnmpPdu pdu = new SnmpPdu(); 
//Specify the Pdu type
pdu.PduType = EnumPduType.GetPdu;
//Set the community string
pdu.Community = "public";
pdu.Version =  SnmpVersion.Version1;

//creat response pdu
SnmpPdu response = null;

// Try to retrieve snmp record
try
{
    // Add snmp variable
    SnmpVariable var = SnmpVariable.CreateSnmpVariable("1.3.6.1.2.1.1.5.0");
    pdu.AddRequestVariables(var);
    // Synchronized 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)
    {
        System.Console.WriteLine("Response oid: "  + response.InnerVariables[0].OID);    
        System.Console.WriteLine("Response value: "  + response.InnerVariables[0].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);
}

Requirements

Namespace: SnmpSource

Assembly: SnmpSource (in SnmpSource.dll)

See Also

SnmpSession Members | SnmpSource Namespace