C# SNMP programming
Asked Answered
H

1

6

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?

Harned answered 29/3, 2011 at 13:22 Comment(4)
Your code formatting is way off (making it very difficult to read) and you're asking way too many questions (some of them are very broad).Billiton
sorry i already edit the question, i just wonder this code isn't it can represent 5 protocol of the SNMPv1 protocl:Harned
5 protocols are get-request, get-next-request,set-request, get-response and trap...Harned
Or #SNMP, sharpsnmplib.codeplex.comCronus
O
7

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

Orelie answered 31/3, 2011 at 19:25 Comment(4)
For any future visitors, do not click the link in this Answer for the SNMPSharpNet Site. This now redirects to a browser extension that Malwarebytes blocked. Here is the address to the github for this project now github.com/rqx110/SnmpSharpNetDisorganization
@Disorganization - are you sure that's the new web site? The authors seem different. The archived former web site points to sourceforge.net/projects/snmpsharpnet/files not github.com/rqx110/SnmpSharpNet.Peavy
You may be correct on the new location for the archive. I really just wanted people to not be able to click on the link that was in the post, as it is DEFINITLY taking you to a malware site now.Disorganization
This is corrected since may 7 2024.Orelie

© 2022 - 2024 — McMap. All rights reserved.