C# SNMP编程

5

我尝试编写一些代码来检索objectID,结果是2B-06-01-04-01-82-31-01-03-01-01。这个值是正确的吗?

// 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);

conn.get("get", argv[0], argv[1], "1.3.6.1.2.1.1.2.0")这段代码的意思是仅执行get协议吗?那set协议呢?


1
你的代码格式有很大问题(让人很难阅读),而且你提出了太多问题(其中一些非常宽泛)。 - RQDQ
抱歉,我已经编辑了问题,我只是想知道这段代码是否可以表示SNMPv1协议的5个协议。 - T_y
5个协议分别为get-request、get-next-request、set-request、get-response和trap。 - T_y
Or #SNMP,http://sharpsnmplib.codeplex.com - Lex Li
1个回答

7
如果你想在C#中使用SNMP,可以尝试使用这个SNMPSharpNet程序集。它非常有用。
这个StackOverflow的答案中,你会发现一个高级用法的示例。
但是请查看文档。你可以以两种方式使用此程序集:
1. 低级别创建自己的SNMP(V1,V2c,V3)PDU 2. 高级别只需使用SNMP
试一试吧。
JP

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接