4

我尝试编写一些代码来检索 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协议?怎么设置?

4

1 回答 1

7

真的,如果您想在 C# 中使用 SNMP,请尝试这个程序集SNMPSharpNet。它非常有用。

您将在此 StackOverflow答案中找到使用它的一种方式(高级)的示例。

但是看看文档。您可以通过两种方式使用此程序集:

  1. 低级别创建您自己的 SNMP(V1、V2c、V3)PDU
  2. 高级别,您只需使用 SNMP

去尝试一下。

J.P

于 2011-03-31T19:25:21.520 回答