C# Class SnmpSharpNet.SimpleSnmp

Utility class to enable simplified access to SNMP version 1 and version 2 requests and replies.
Use this class if you are not looking for "deep" SNMP functionality. Design of the class is based around providing simplest possible access to SNMP operations without getting stack into details. If you are using the simplest way, you will leave SuppressExceptions flag to true and get all errors causing methods to return "null" result which will not tell you why operation failed. You can change the SuppressExceptions flag to false and catch any and all exception throwing errors. Either way, have fun.
显示文件 Open project: griffina/SnmpSharpNet Class Usage Examples

Protected Properties

Property Type Description
_community string
_maxRepetitions int
_nonRepeaters int
_peerIP System.Net.IPAddress
_peerName string
_peerPort int
_retry int
_suppressExceptions bool
_target UdpTarget
_timeout int

Public Methods

Method Description
Get ( SnmpVersion version, Pdu pdu ) : AsnType>.Dictionary

SNMP GET request

Get ( SnmpVersion version, string oidList ) : AsnType>.Dictionary

SNMP GET request

GetBulk ( Pdu pdu ) : AsnType>.Dictionary

SNMP GET-BULK request

GetBulk request type is only available with SNMP v2c agents. SNMP v3 also supports the request itself but that version of the protocol is not supported by SimpleSnmp. GetBulk method will return a dictionary of Oid to value mapped values as returned form a single GetBulk request to the agent. You can change how the request itself is made by changing the SimpleSnmp.NonRepeaters and SimpleSnmp.MaxRepetitions values. SimpleSnmp properties are only used when values in the parameter Pdu are set to 0.

GetBulk ( string oidList ) : AsnType>.Dictionary

SNMP GET-BULK request

Performs a GetBulk SNMP v2 operation on a list of OIDs. This is a convenience function that calls GetBulk(Pdu) method.

GetNext ( SnmpVersion version, Pdu pdu ) : AsnType>.Dictionary

SNMP GET-NEXT request

GetNext ( SnmpVersion version, string oidList ) : AsnType>.Dictionary

SNMP GET-NEXT request

Set ( SnmpVersion version, Pdu pdu ) : AsnType>.Dictionary

SNMP SET request

Set ( SnmpVersion version, Vb vbs ) : AsnType>.Dictionary

SNMP SET request

SimpleSnmp ( ) : System

Constructor.

Class is initialized to default values. Peer IP address is set to loopback, peer port number to 161, timeout to 2000 ms (2 seconds), retry count to 2 and community name to public.

SimpleSnmp ( string peerName ) : System

Constructor.

Class is initialized with default values with the agent name set to the supplied DNS name (or IP address). If peer name is a DNS name, DNS resolution will take place in the constructor attempting to resolve it an IP address.

SimpleSnmp ( string peerName, int peerPort, string community ) : System

Constructor.

SimpleSnmp ( string peerName, int peerPort, string community, int timeout, int retry ) : System

Constructor.

SimpleSnmp ( string peerName, string community ) : System

Constructor

Walk ( SnmpVersion version, string rootOid ) : AsnType>.Dictionary

SNMP WALK operation

When using SNMP version 1, walk is performed using GET-NEXT calls. When using SNMP version 2, walk is performed using GET-BULK calls.

Walk ( bool tryGetBulk, SnmpVersion version, string rootOid ) : AsnType>.Dictionary

SNMP WALK operation

When using SNMP version 1, walk is performed using GET-NEXT calls. When using SNMP version 2, walk is performed using GET-BULK calls.

Private Methods

Method Description
Resolve ( ) : bool

Resolve peer name to an IP address

This method will not throw any exceptions, even on failed DNS resolution. Make sure you call SimpleSnmp.Valid property to verify class state.

Method Details

Get() public method

SNMP GET request
public Get ( SnmpVersion version, Pdu pdu ) : AsnType>.Dictionary
version SnmpVersion SNMP protocol version. Acceptable values are SnmpVersion.Ver1 and SnmpVersion.Ver2
pdu Pdu Request Protocol Data Unit
return AsnType>.Dictionary

Get() public method

SNMP GET request
public Get ( SnmpVersion version, string oidList ) : AsnType>.Dictionary
version SnmpVersion SNMP protocol version number. Acceptable values are SnmpVersion.Ver1 and SnmpVersion.Ver2
oidList string List of request OIDs in string dotted decimal format.
return AsnType>.Dictionary

GetBulk() public method

SNMP GET-BULK request
GetBulk request type is only available with SNMP v2c agents. SNMP v3 also supports the request itself but that version of the protocol is not supported by SimpleSnmp. GetBulk method will return a dictionary of Oid to value mapped values as returned form a single GetBulk request to the agent. You can change how the request itself is made by changing the SimpleSnmp.NonRepeaters and SimpleSnmp.MaxRepetitions values. SimpleSnmp properties are only used when values in the parameter Pdu are set to 0.
public GetBulk ( Pdu pdu ) : AsnType>.Dictionary
pdu Pdu Request Protocol Data Unit
return AsnType>.Dictionary

GetBulk() public method

SNMP GET-BULK request
Performs a GetBulk SNMP v2 operation on a list of OIDs. This is a convenience function that calls GetBulk(Pdu) method.
public GetBulk ( string oidList ) : AsnType>.Dictionary
oidList string List of request OIDs in string dotted decimal format.
return AsnType>.Dictionary

GetNext() public method

SNMP GET-NEXT request
public GetNext ( SnmpVersion version, Pdu pdu ) : AsnType>.Dictionary
version SnmpVersion SNMP protocol version. Acceptable values are SnmpVersion.Ver1 and SnmpVersion.Ver2
pdu Pdu Request Protocol Data Unit
return AsnType>.Dictionary

GetNext() public method

SNMP GET-NEXT request
public GetNext ( SnmpVersion version, string oidList ) : AsnType>.Dictionary
version SnmpVersion SNMP protocol version number. Acceptable values are SnmpVersion.Ver1 and SnmpVersion.Ver2
oidList string List of request OIDs in string dotted decimal format.
return AsnType>.Dictionary

Set() public method

SNMP SET request
public Set ( SnmpVersion version, Pdu pdu ) : AsnType>.Dictionary
version SnmpVersion SNMP protocol version number. Acceptable values are SnmpVersion.Ver1 and SnmpVersion.Ver2
pdu Pdu Request Protocol Data Unit
return AsnType>.Dictionary

Set() public method

SNMP SET request
public Set ( SnmpVersion version, Vb vbs ) : AsnType>.Dictionary
version SnmpVersion SNMP protocol version number. Acceptable values are SnmpVersion.Ver1 and SnmpVersion.Ver2
vbs Vb Vb array containing Oid/AsnValue pairs for the SET operation
return AsnType>.Dictionary

SimpleSnmp() public method

Constructor.
Class is initialized to default values. Peer IP address is set to loopback, peer port number to 161, timeout to 2000 ms (2 seconds), retry count to 2 and community name to public.
public SimpleSnmp ( ) : System
return System

SimpleSnmp() public method

Constructor.
Class is initialized with default values with the agent name set to the supplied DNS name (or IP address). If peer name is a DNS name, DNS resolution will take place in the constructor attempting to resolve it an IP address.
public SimpleSnmp ( string peerName ) : System
peerName string Peer name or IP address
return System

SimpleSnmp() public method

Constructor.
public SimpleSnmp ( string peerName, int peerPort, string community ) : System
peerName string Peer name or IP address
peerPort int Peer UDP port number
community string SNMP community name
return System

SimpleSnmp() public method

Constructor.
public SimpleSnmp ( string peerName, int peerPort, string community, int timeout, int retry ) : System
peerName string Peer name or IP address
peerPort int Peer UDP port number
community string SNMP community name
timeout int SNMP request timeout
retry int Maximum number of retries excluding the first request (0 = 1 request is sent)
return System

SimpleSnmp() public method

Constructor
public SimpleSnmp ( string peerName, string community ) : System
peerName string Peer name or IP address
community string SNMP community name
return System

Walk() public method

SNMP WALK operation
When using SNMP version 1, walk is performed using GET-NEXT calls. When using SNMP version 2, walk is performed using GET-BULK calls.
public Walk ( SnmpVersion version, string rootOid ) : AsnType>.Dictionary
version SnmpVersion SNMP protocol version. Acceptable values are SnmpVersion.Ver1 and /// SnmpVersion.Ver2
rootOid string OID to start WALK operation from. Only child OIDs of the rootOid will be /// retrieved and returned
return AsnType>.Dictionary

Walk() public method

SNMP WALK operation
When using SNMP version 1, walk is performed using GET-NEXT calls. When using SNMP version 2, walk is performed using GET-BULK calls.
public Walk ( bool tryGetBulk, SnmpVersion version, string rootOid ) : AsnType>.Dictionary
tryGetBulk bool this param is used to use get bulk on V2 requests
version SnmpVersion SNMP protocol version. Acceptable values are SnmpVersion.Ver1 and /// SnmpVersion.Ver2
rootOid string OID to start WALK operation from. Only child OIDs of the rootOid will be /// retrieved and returned
return AsnType>.Dictionary

Property Details

_community protected_oe property

SNMP community name
protected string _community
return string

_maxRepetitions protected_oe property

Maximum repetitions value used in SNMP GET-BULK requests
protected int _maxRepetitions
return int

_nonRepeaters protected_oe property

Non repeaters value used in SNMP GET-BULK requests
protected int _nonRepeaters
return int

_peerIP protected_oe property

SNMP Agents IP address
protected IPAddress,System.Net _peerIP
return System.Net.IPAddress

_peerName protected_oe property

SNMP Agents name
protected string _peerName
return string

_peerPort protected_oe property

SNMP Agent UDP port number
protected int _peerPort
return int

_retry protected_oe property

Maximum retry count excluding the first request
protected int _retry
return int

_suppressExceptions protected_oe property

Flag determines if exceptions are suppressed or thrown. When exceptions are suppressed, methods return null on errors regardless of what the error is.
protected bool _suppressExceptions
return bool

_target protected_oe property

Target class
protected UdpTarget,SnmpSharpNet _target
return UdpTarget

_timeout protected_oe property

Timeout value in milliseconds
protected int _timeout
return int