Simple Network Management Protocol Open Source library written in c# with support for SNMP version 1, 2c and 3.

Classes

  ClassDescription
AgentParameters
SNMP Agent specific values. This class stores values to access SNMP version 1 and version 2 agents. Pass this class with your request data (Pdu) to the request method of the target class to make a request.
AsnType
Base class for all ASN.1 value classes
Authentication
Helper class to make dealing with multiple (if 2 qualifies as multiple) authentication protocols in a transparent way. Calling class keeps the authentication protocol selection (as defined on the agent) in an integer variable that can have 3 values: None, MD5, or SHA1. Using GetInstance(AuthenticationDigests), calling method can get authentication protocol implementation class instance cast as IAuthenticationDigest interface and perform authentication operations (either authenticate outgoing packets to verify authentication of incoming packets) without needing to further care about which authentication protocol is used. Example of how to use this class:
CopyC#
IAuthenticationDigest authenticationImplementation = Authentication.GetInstance(AuthenticationDigests.MD5);
authenticationImplementation.authenticateIncomingMsg(...);
authenticationImplementation.authenticateOutgoingMsg(...);
AuthenticationMD5
MD5 Authentication class.
AuthenticationSHA1
SHA-1 Authentication class.
Counter32
Defines a SNMPv1 32-bit counter object. The object is a 32-bit unsigned value that is incremented periodically by an agent normally. The object inherits and uses most of the methods defined by the UInteger32 class. This class does not define any specific data, but is instead used to override the ASN.1 type of the base class.
Counter64
ASN.1 Counter64 value implementation.
EndOfMibView
Returned when end of MIB has been reached when performing GET-NEXT or GET-BULK operations.
EthernetAddress
EthernetAddress class encapsulates a 6 byte OctetString representing an Ethernet MAC address.
Gauge32
ASN.1 Gauge32 value class.
Integer32
This class defines the SNMP 32-bit signed integer used by the SNMP SMI. This class also serves as a base class for any additional SNMP SMI types that exits now or may be defined in the future.
IpAddress
IpAddress class extends the OctetString class and accomodates IP address values passed to or returned by SNMP agents. Example:
CopyC#
IpAddress ipaddr = new IpAddress("10.1.1.1");
MsgFlags
Message flags in the SNMP v3 header. Message flags hold flags that indicate if packet is authenticated, privacy protected and if report reply is expected on errors. Message flags field is a 1 byte OctetString encoded field.
MutableByte
Mutable byte class allows for manipulation of a byte array with operations like append, prepend. Functionality is implemented through temporary buffer creation and data duplication.
CopyC#
MutableByte buffer = new MutableByte();
buffer += "test data";
buffer.Append(". More test data");
buffer.Prepend("This is ");
Console.WriteLine(buffer.ToString()); // Prints out "This is test data. More test data"
buffer.RemoveBeginning(8); // The buffer now holds "test data. More test data"
buffer.Prepend("It could be "); // buffer is "It could be test data. More test data"
buffer.RemoveEnd(" More test data".Length); // buffer: "It could be test data."
buffer.Remove(12,5); // buffer: "It could be data"
Console.WriteLine("{0}",Convert.ToChar(buffer[1])); // Output: "t"
byte[] tmpBuffer = buffer; // Implicit conversion to byte[]
buffer.Reset(); // Erase all the data from the buffer
NoSuchInstance
Returned when requested instance is not present in a table of an SNMP version 2 agent.
NoSuchObject
NoSuchObject is returned by the agent in response to a SNMP version 2 request when requested object does not exist in its MIB. This value is returned as a with data of length 0 For example:
CopyC#
[... prepare for a get operation ...]
Pdu response = target.request(outpdu);
foreach(Vb vb in response.VbList) {
    if( vb.Value is NoSuchObject ) {
        return "Requested MIB variable does not exist on the agent.";
    }
}
Null
ASN.1 Null value implementation.
OctetString
ASN.1 OctetString implementation
Oid
ASN.1 ObjectId type implementation
Opaque
The Opaque class is an extension of the octet string class and is used to pass opaque data. Opaque data is information that isn't interperted by the manager in general.
Pdu
SNMP PDU class that is the bases for all SNMP requests and replies. It is capable of processing SNMPv1 GET, GET-NEXT, REPLY and SNMPv2 GET, GET-NEXT, GET-BULK, REPLY, V2TRAP, INFORM and REPORT PDUs.
CopyC#
Pdu pdu = new Pdu();
pdu.Type = SnmpConstants.GET;
pdu.VbList = new Vbs();
pdu.VbList.AddVb("1.3.6.1.2.1.1.1.0");
pdu.VbList.AddVb("1.3.6.1.2.1.1.2.0");
PrivacyAES
AES privacy protocol implementation class. This class implements 128, 192 and 256-bit key versions of the privacy protocol.
PrivacyAES128
AES 128-bit key size privacy protocol implementation class.
PrivacyDES
SNMP Version 3 DES privacy protocol implementation. DES requires an encryption key be provided of 16 bytes in length. Class will accept longer key values (which will be trimmed to 16 bytes) but both encrypt and decrypt operations will fail if key is shorter then required value length. Decryption operation depends on USM header privacyParameters field value which is generated by the Encrypt method. Make sure privacyParameters argument value is correctly inserted into the target packet to enable SNMP agent to decrypt the message.
PrivacyProtocol
Privacy protocol helper class. This class is used to define privacy protocol encryption type in other classes using integer constants representing each protocol supported, and allows for easy instantiation of privacy protocol when used for encryption or decryption of data in a encryption method independent way. Example of how to use this class:
CopyC#
int myPrivacyProtocol = PrivacyProtocol.AES128;

IPrivacyProtocol privacyImplementation = PrivacyProtocol.GetInstance(myPrivacyProtocol);
byte[] result = privacyImplementation.Encrypt(....);
ScopedPdu
SNMP Version 3 Scoped Protocol Data Unit. ScopedPdu extends the Pdu class by adding SNMP version 3 specific Context Engine Id and Context Name variables to the beginning of the packet. Context engine id is retrieved from the agent using the SNMP version 3 standard defined discovery process. Context name is used to define which subsection of the agents MIB user is allowed (or wants) to access. When creating a new ScopedPdu, for a valid request, ContextEngineId value has to be set for a valid reply to be received. Context value is implementation specific (depends on the configuration of the agent) and might not be required for a successful request.
SecureAgentParameters
SNMP Agent specific values. This class stores values to access SNMP version 3 agents. Pass this class with your request data (Pdu) to the request method of the target class to make a request. Based on the information in this class, an appropriate request will be made by the request class. Following request types are generated: * if EngineBoots and EngineTime are integer value 0 or if EngineId value is length 0, Discovery request is made and passed instance of the SecureAgentParameters is updated with returned values. * in all other cases, SNMP request is made to the agent
Sequence
Represents SNMP sequence
SnmpAgentException
Exception thrown when SNMP version 3 agent returns an error Oid in response to a request.
SnmpConstants
SNMP SMI v1 and v2 constants.
SnmpDecodingException
Exception thrown on failure to decode BER encoded information.
SnmpError
Helper class provides translation of SNMP version 1 and 2 error status codes to short, descriptive error messages. To use, call the static member ErrorMessage(Int32). Example:
CopyC#
SnmpError.ErrorMessage(12);
SnmpException
SNMP generic exception. Thrown every time SNMP specific error is encountered.
SnmpInvalidSecurityModelException
Exception thrown when SNMP version 3 packet is returned with security model code not equal to USM
SnmpMessageTimeWindowException
Exception thrown during decoding of SNMP version 3 messages when received authoritative engine time is outside of the time window (150 seconds). Security state reference discovery needs to be performed again to sync time between the agent and manager.
SnmpNetworkException
Exception thrown when network error was encountered. Network errors include host, network unreachable, connection refused, etc. One network exception that is not covered by this exception is request timeout.
SnmpPacket
Base SNMP packet class. All SNMP packets begin with the SMI_SEQUENCE header and SNMP protocol version number. This class parses and encodes these values. Derived classes parse further information from SNMP packets.
SnmpRequestTimeoutException
Exception thrown when SNMP request timed out.
SnmpSecurityException
Exception thrown when Authentication and Privacy flags in the response do not match what was sent in the request.
SnmpV1Packet
SNMP version 1 packet class. Supported types are SNMP-GET, SNMP-GETNEXT and SNMP-SET. Available packet classes are: This class is provided to simplify encoding and decoding of packets and to provide consistent interface for users who wish to handle transport part of protocol on their own without using the UdpTarget class. SnmpPacket and derived classes have been developed to implement SNMP version 1, 2 and 3 packet support. For SNMP version 1 and 2 packet, SnmpV1Packet and SnmpV2Packet classes provides sufficient support for encoding and decoding data to/from BER buffers to satisfy requirements of most applications. SNMP version 3 on the other hand requires a lot more information to be passed to the encoder method and returned by the decode method. While using SnmpV3Packet class for full packet handling is possible, transport specific class UdpTarget uses SecureAgentParameters class to store protocol version 3 specific information that carries over from request to request when used on the same SNMP agent and therefore simplifies both initial definition of agents configuration (mostly security) as well as removes the need for repeated initialization of the packet class for subsequent requests. If you decide not to use transport helper class(es) like UdpTarget, BER encoding and decoding and packets is easily done with SnmpPacket derived classes. Example, SNMP version 1 packet encoding:
CopyC#
SnmpV1Packet packetv1 = new SnmpV1Packet();
packetv1.SnmpCommunity.Set("public");
packetv1.Pdu.Set(mypdu);
byte[] berpacket = packetv1.encode();
Example, SNMP version 1 packet decoding:
CopyC#
SnmpV1Packet packetv1 = new SnmpV1Packet();
packetv1.decode(inbuffer,inlen);
Example, SNMP version 2 packet encoding:
CopyC#
SnmpV2Packet packetv2 = new SnmpV2Packet();
packetv2.SnmpCommunity.Set("public");
packetv2.Pdu.Set(mypdu);
byte[] berpacket = packetv2.encode();
Example, SNMP version 2 packet decoding:
CopyC#
SnmpV2Packet packetv2 = new SnmpV2Packet();
packetv2.decode(inbuffer,inlen);
Example, SNMP version 3 noAuthNoPriv encoding:
CopyC#
SnmpV3Packet packetv3 = new SnmpV3Packet();
packetv3.noAuthNoPriv("myusername");
packetv3.SetEngineTime(engineTime, engineBoots); // See SNMPv3 discovery process for details
packetv3.SetEngineId(engineId); // See SNMPv3 discovery process for details
packetv3.IsReportable = true;
packetv3.Pdu.Set(mypdu);
byte[] berpacket = packetv3.encode();
Example, SNMP version 3 authNoPriv using MD5 authentication packet encoding:
CopyC#
SnmpV3Packet packetv3 = new SnmpV3Packet();
packetv3.authNoPriv("myusername", "myAuthenticationPassword", AuthenticationDigests.MD5);
packetv3.SetEngineTime(engineTime, engineBoots); // See SNMPv3 discovery process for details
packetv3.SetEngineId(engineId); // See SNMPv3 discovery process for details
packetv3.IsReportable = true;
packetv3.Pdu.Set(mypdu);
byte[] berpacket = packetv3.encode();
Example, SNMP version 3 authPriv using MD5 authentication and DES encryption packet encoding:
CopyC#
SnmpV3Packet packetv3 = new SnmpV3Packet();
packetv3.authPriv("myusername", "myAuthenticationPassword", AuthenticationDigests.MD5,
       "myPrivacyPassword", PrivacyProtocols.DES);
packetv3.SetEngineTime(engineTime, engineBoots); // See SNMPv3 discovery process for details
packetv3.SetEngineId(engineId); // See SNMPv3 discovery process for details
packetv3.IsReportable = true;
packetv3.Pdu.Set(mypdu);
byte[] berpacket = packetv3.encode();
When decoding SNMP version 3 packets, SnmpV3Packet class needs to be initialized with the same values security values as a request does. This includes, authoritative engine id, engine boots and engine time, if authentication is used, authentication digest and password and for encryption, password and privacy protocol used. Without these parameters packet class will not be able to verify the incoming packet and responses will be discareded even if they are valid.
SnmpV1TrapPacket
SNMP version 1 TRAP packet class. Available packet classes are: This class is provided to simplify encoding and decoding of packets and to provide consistent interface for users who wish to handle transport part of protocol on their own without using the UdpTarget class. SnmpPacket and derived classes have been developed to implement SNMP version 3 packet support. For SNMP version 1 and 2 packet, SnmpV1Packet and SnmpV2Packet classes provides sufficient support for encoding and decoding data to/from BER buffers to satisfy requirements of most applications. SNMP version 3 on the other hand requires a lot more information to be passed to the encoder method and returned by the decode method. Attempt of implementing SNMP version 3 as part of SnmpV3Packet class was operational but required too many function arguments to operate so a different interface was developed using dedicated SnmpV3Packet class.
SnmpV2Packet
SNMP version 2 packet. This class is the same as SNMPV1Packet. Available packet classes are: This class is provided to simplify encoding and decoding of packets and to provide consistent interface for users who wish to handle transport part of protocol on their own without using the UdpTarget class. SnmpPacket and derived classes have been developed to implement SNMP version 1, 2 and 3 packet support. For SNMP version 1 and 2 packet, SnmpV1Packet and SnmpV2Packet classes provides sufficient support for encoding and decoding data to/from BER buffers to satisfy requirements of most applications. SNMP version 3 on the other hand requires a lot more information to be passed to the encoder method and returned by the decode method. While using SnmpV3Packet class for full packet handling is possible, transport specific class UdpTarget uses SecureAgentParameters class to store protocol version 3 specific information that carries over from request to request when used on the same SNMP agent and therefore simplifies both initial definition of agents configuration (mostly security) as well as removes the need for repeated initialization of the packet class for subsequent requests. If you decide not to use transport helper class(es) like UdpTarget, BER encoding and decoding and packets is easily done with SnmpPacket derived classes. Example, SNMP version 1 packet encoding:
CopyC#
SnmpV1Packet packetv1 = new SnmpV1Packet();
packetv1.SnmpCommunity.Set("public");
packetv1.Pdu.Set(mypdu);
byte[] berpacket = packetv1.encode();
Example, SNMP version 1 packet decoding:
CopyC#
SnmpV1Packet packetv1 = new SnmpV1Packet();
packetv1.decode(inbuffer,inlen);
Example, SNMP version 2 packet encoding:
CopyC#
SnmpV2Packet packetv2 = new SnmpV2Packet();
packetv2.SnmpCommunity.Set("public");
packetv2.Pdu.Set(mypdu);
byte[] berpacket = packetv2.encode();
Example, SNMP version 2 packet decoding:
CopyC#
SnmpV2Packet packetv2 = new SnmpV2Packet();
packetv2.decode(inbuffer,inlen);
Example, SNMP version 3 noAuthNoPriv encoding:
CopyC#
SnmpV3Packet packetv3 = new SnmpV3Packet();
packetv3.noAuthNoPriv("myusername");
packetv3.SetEngineTime(engineTime, engineBoots); // See SNMPv3 discovery process for details
packetv3.SetEngineId(engineId); // See SNMPv3 discovery process for details
packetv3.IsReportable = true;
packetv3.Pdu.Set(mypdu);
byte[] berpacket = packetv3.encode();
Example, SNMP version 3 authNoPriv using MD5 authentication packet encoding:
CopyC#
SnmpV3Packet packetv3 = new SnmpV3Packet();
packetv3.authNoPriv("myusername", "myAuthenticationPassword", AuthenticationDigests.MD5);
packetv3.SetEngineTime(engineTime, engineBoots); // See SNMPv3 discovery process for details
packetv3.SetEngineId(engineId); // See SNMPv3 discovery process for details
packetv3.IsReportable = true;
packetv3.Pdu.Set(mypdu);
byte[] berpacket = packetv3.encode();
Example, SNMP version 3 authPriv using MD5 authentication and DES encryption packet encoding:
CopyC#
SnmpV3Packet packetv3 = new SnmpV3Packet();
packetv3.authPriv("myusername", "myAuthenticationPassword", AuthenticationDigests.MD5,
       "myPrivacyPassword", PrivacyProtocols.DES);
packetv3.SetEngineTime(engineTime, engineBoots); // See SNMPv3 discovery process for details
packetv3.SetEngineId(engineId); // See SNMPv3 discovery process for details
packetv3.IsReportable = true;
packetv3.Pdu.Set(mypdu);
byte[] berpacket = packetv3.encode();
When decoding SNMP version 3 packets, SnmpV3Packet class needs to be initialized with the same values security values as a request does. This includes, authoritative engine id, engine boots and engine time, if authentication is used, authentication digest and password and for encryption, password and privacy protocol used. Without these parameters packet class will not be able to verify the incoming packet and responses will be discareded even if they are valid.
SnmpV3Packet
SNMP version 3 packet implementation class. Available packet classes are: This class is provided to simplify encoding and decoding of packets and to provide consistent interface for users who wish to handle transport part of protocol on their own without using the UdpTarget class. SnmpPacket and derived classes have been developed to implement SNMP version 1, 2 and 3 packet support. For SNMP version 1 and 2 packet, SnmpV1Packet and SnmpV2Packet classes provides sufficient support for encoding and decoding data to/from BER buffers to satisfy requirements of most applications. SNMP version 3 on the other hand requires a lot more information to be passed to the encoder method and returned by the decode method. While using SnmpV3Packet class for full packet handling is possible, transport specific class UdpTarget uses SecureAgentParameters class to store protocol version 3 specific information that carries over from request to request when used on the same SNMP agent and therefore simplifies both initial definition of agents configuration (mostly security) as well as removes the need for repeated initialization of the packet class for subsequent requests. If you decide not to use transport helper class(es) like UdpTarget, BER encoding and decoding and packets is easily done with SnmpPacket derived classes. Example, SNMP version 1 packet encoding:
CopyC#
SnmpV1Packet packetv1 = new SnmpV1Packet();
packetv1.SnmpCommunity.Set("public");
packetv1.Pdu.Set(mypdu);
byte[] berpacket = packetv1.encode();
Example, SNMP version 1 packet decoding:
CopyC#
SnmpV1Packet packetv1 = new SnmpV1Packet();
packetv1.decode(inbuffer,inlen);
Example, SNMP version 2 packet encoding:
CopyC#
SnmpV2Packet packetv2 = new SnmpV2Packet();
packetv2.SnmpCommunity.Set("public");
packetv2.Pdu.Set(mypdu);
byte[] berpacket = packetv2.encode();
Example, SNMP version 2 packet decoding:
CopyC#
SnmpV2Packet packetv2 = new SnmpV2Packet();
packetv2.decode(inbuffer,inlen);
Example, SNMP version 3 noAuthNoPriv encoding:
CopyC#
SnmpV3Packet packetv3 = new SnmpV3Packet();
packetv3.noAuthNoPriv("myusername");
packetv3.SetEngineTime(engineTime, engineBoots); // See SNMPv3 discovery process for details
packetv3.SetEngineId(engineId); // See SNMPv3 discovery process for details
packetv3.IsReportable = true;
packetv3.Pdu.Set(mypdu);
byte[] berpacket = packetv3.encode();
Example, SNMP version 3 authNoPriv using MD5 authentication packet encoding:
CopyC#
SnmpV3Packet packetv3 = new SnmpV3Packet();
packetv3.authNoPriv("myusername", "myAuthenticationPassword", AuthenticationDigests.MD5);
packetv3.SetEngineTime(engineTime, engineBoots); // See SNMPv3 discovery process for details
packetv3.SetEngineId(engineId); // See SNMPv3 discovery process for details
packetv3.IsReportable = true;
packetv3.Pdu.Set(mypdu);
byte[] berpacket = packetv3.encode();
Example, SNMP version 3 authPriv using MD5 authentication and DES encryption packet encoding:
CopyC#
SnmpV3Packet packetv3 = new SnmpV3Packet();
packetv3.authPriv("myusername", "myAuthenticationPassword", AuthenticationDigests.MD5,
       "myPrivacyPassword", PrivacyProtocols.DES);
packetv3.SetEngineTime(engineTime, engineBoots); // See SNMPv3 discovery process for details
packetv3.SetEngineId(engineId); // See SNMPv3 discovery process for details
packetv3.IsReportable = true;
packetv3.Pdu.Set(mypdu);
byte[] berpacket = packetv3.encode();
When decoding SNMP version 3 packets, SnmpV3Packet class needs to be initialized with the same values security values as a request does. This includes, authoritative engine id, engine boots and engine time, if authentication is used, authentication digest and password and for encryption, password and privacy protocol used. Without these parameters packet class will not be able to verify the incoming packet and responses will be discareded even if they are valid.
SNMPV3ReportError
SNMP class translates SNMP version 3 report errors into error strings.
TimeTicks
ASN.1 TimeTicks value representation. Value is stored as an unsigned 32-bit integer and stores the number of 1/100s of a second periods of uptime.
TrapPdu
SNMP version 1 TRAP Protocol Data Unit class. Use it to encode/decode SNMPv1 trap PDUs and allow access to trap values. This is a unique PDU type and is replaced by the standard PDU layout in version 2 (no special PDU for traps).
UdpTarget
InternetProtocol version 4 User Datagram Protocol (IP/UDP) transport protocol implementation for use with SNMP versions 1, 2 and 3. See example programs included for usage samples.
UdpTransport
IP/UDP transport class.
UInteger32
ASN.1 unsigned 32-bit integer value class.
UserSecurityModel
User security model implementation class.
V2Error
Base class for SNMP version 2 error type. For details see NoSuchInstance, NoSuchObject and EndOfMibView.
V2PartyClock
Defines an SNMPv2 Party Clock. The Party Clock is currently Obsolete, but included for backwards compatibility. Obsoleted in RFC 1902.
Vb
Vb item. Stores Oid => value pair for each value
VbCollection
Just a placeholder class extending ArrayList class dedicated to hold the Vb collection

Interfaces

  InterfaceDescription
IAgentParameters
Every agent parameters class implements this interface
IAuthenticationDigest
Authentication digest interface. Interface defines authentication methods for incoming and outgoing requests.
IPrivacyProtocol
Privacy protocol interface. Defines encryption and decryption methods for all privacy protocols allowing for any of the available protocols to be cast as the interface and called to perform privacy operations on packets.

Delegates

  DelegateDescription
SnmpAsyncResponse
Callback used to pass result of an async SNMP operation back to the caller.

Enumerations

  EnumerationDescription
AsyncRequestResult
Result codes sent by UdpTarget class to the SnmpAsyncCallback delegate.
AuthenticationDigests
Enumeration of available authentication digests
PrivacyProtocols
Available privacy protocol enumeration.
SnmpVersion
SNMP Version number enumeration