T_y
T_y

Reputation: 99

SNMP programming with Richard Blum's sample code

I try write some code to retrieve objectID and the result is 2B-06-01-04-01-82-31-01-03-01-01. Isn't this value correct?

// Send a SysObjectId SNMP request
response = conn.get("get", argv[0], argv[1], "1.3.6.1.2.1.1.2.0");
if (response[0] == 0xff)
{
    Console.WriteLine("No response from {0}", argv[0]);
    return;
}

// Get the community and MIB lengths of the response
commlength = Convert.ToInt16(response[6]);
miblength = Convert.ToInt16(response[23 + commlength]);

// Extract the MIB data from the SNMp response
datatype = Convert.ToInt16(response[24 + commlength + miblength]);
datalength = Convert.ToInt16(response[25 + commlength + miblength]);
datastart = 26 + commlength + miblength;
output= BitConverter.ToString(response, datastart, datalength);
Console.WriteLine("  sysObjectId - Datatype: {0}, Value: {1}",
       datatype, output);

Does conn.get("get", argv[0], argv[1], "1.3.6.1.2.1.1.2.0") mean that it only executes get protocol? How about set?

Upvotes: 6

Views: 42093

Answers (2)

Lex Li
Lex Li

Reputation: 63123

Further digging into the sample code you provided, we can see that you were following the C# Network Programming book written by Richard Blum.

Unfortunately the chapter 12 (in its 2006 edition) contains just preliminary information on how to use SNMP in a professional application development process, so it is not very helpful for developers in their daily work. Therefore, you have to choose from libraries either from commercial vendors, or from the open source community.

#SNMP, https://sharpsnmp.com, has been there since Apr 2008 and is still well maintained by my company,

  • Full SNMP feature support (v1, v2c, v3) and more.
  • Support the latest .NET Framework and .NET platforms.
  • Utilize the new platform features to deliver the best performance.
  • Frequent releases to address known issues
  • (Optional) Commercial addon #SNMP Pro covers enterprise MIB support.

Other open source projects in this field such as SNMP#NET (SnmpSharpNet) are either abandoned by their authors, out of maintenance for years, or lack of essential SNMP features.

References

Upvotes: 0

JPBlanc
JPBlanc

Reputation: 72612

Really if you want to work with SNMP in C# try this assembly SNMPSharpNet or NuGet package. It' very useful.

You will find in this StackOverflow answer an example of one way (high level) to use it.

But look at the documentation. You can use this assembly in two ways :

  1. Low level to create your own SNMP (V1, V2c, V3) PDUs
  2. High level, where you just use SNMP

Just try it.

JP

Upvotes: 7

Related Questions