简体   繁体   English

C#SNMP编程

[英]C# SNMP programming

I try write some code to retrieve objectID and the result is 2B-06-01-04-01-82-31-01-03-01-01 . 我尝试编写一些代码来检索objectID,结果为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? conn.get("get", argv[0], argv[1], "1.3.6.1.2.1.1.2.0")意味着仅执行get协议吗? How about set? 怎么样?

Really if you want to work with SNMP in C# try this assembly SNMPSharpNet . 真的,如果您想在C#中使用SNMP,请尝试使用此程序集SNMPSharpNet It' very useful. 非常有用

You will find in this StackOverflow answer an example of one way (high level) to use it. 您将在此StackOverflow答案中找到一个使用它的一种方式(高级)的示例。

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 低级创建自己的SNMP(V1,V2c,V3)PDU
  2. High level, where you just use SNMP 高层,您仅使用SNMP

Just try it. 去尝试一下。

JP J.P

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM