Simple SNMP with simplesnmp

Source: Internet
Author: User

Apparently not everybody is as interested in the background workings of the SNMP protocol as I am. for this reason I have created a very simple to use utility class that will allow you to make requests and collect replies without worrying too much about how it's all done.

For that reason I have created simplesnmp class. it makes common SNMP Version 1 and 2c operations simple. version 3 is not supported ded because there is a security aspect that, if simplified too much, will no longer be secure.

To dive straight in, here is a SNMP-GET request example:

 String Host =   "Localhost"  ;  String Community =   "Public"  ; Simplesnmp SNMP =   New Simplesnmp ( Host, community)  ;  If   (  ! SNMP. Valid  )  { Console. Writeline  (  "SNMP agent host name/IP address is invalid ."  )  ; Return ;  } Dictionary< OID, asntype > Result = SNMP. Get  ( Snmpversion. Ver1 , New   String  [  ]   {   ". 1.3.6.1.2.1.1.1.0"  }   )  ; If   ( Result =   Null  )  { Console. Writeline  (  "No results received ."  )  ; Return ;  }  Foreach   ( Keyvaluepair kVpIn Result )  { Console. Writeline  (  "{0 }:{ 1} {2 }" , KVp. Key . Tostring  (  ) , Snmpconstants. Gettypename  ( KVp. Value . Type ) , KVp. Value . Tostring  (  )  )  ;  } 

On my laptop, result looks like this:

 
1.3.6.1.2.1.1.1.0: octetstring "dual core intel notebook"

Obviusly, you can request multiple values in a single request just by adding them to the simplesnmp. Get () oId string array.

Methods are also available for getnext:

Dictionary < OID, asntype > Result = SNMP. Getnext  ( Snmpversion. Ver2 , New   String  [  ]   {                                                           ". 1.3.6.1.2.1.1.1" , ". 1.3.6.1.2.1.1.2"                                                      }   )  ; 

GETBULK:

 dictionary   OID, asntype > result = SNMP.  GETBULK   (  New   string   [ ]  {  ". 1.3.6.1.2 ",  ". 1.3.6.1.3 " } )  ; 

Set:

Dictionary < OID, asntype > Result = SNMP. Set  ( Snmpversion. Ver2 , New VB [  ]   {                                                       New VB (  New Oid (  ". 1.3.6.1.2.1.1.1.0"  ) , New Octetstring (  "New sysdescr.0"  )                                                      }   )  ; 

And walk:

 
Dictionary result=SNMP.Walk(Snmpversion.Ver2,". 1.3.6.1.2.1.1.1");

Simplesnmp. Walk uses GETBULK with SNMP Version 2C. If SNMP Version 1 is selected, getnext operation is used and is considerably slower.

To control how GETBULK and SNMP Version 2 walk performs, you can set simplesnmp. nonrepeaters and simplesnmp. MaxRepetitions values to adjust how getbulk cils are made.

Prior to using the class, you can check the status of the simplesnmp. valid property to verify class is in correctly initialized. this property will validate that agent name was correctly resolved to an IP address and that community name is set.

 

From: http://www.snmpsharpnet.com/node/19

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.