You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

SNMP#NET添加OID查询Windows CPU温度报错及额外OID添加咨询

Understanding the SNMP#NET Error and Correctly Adding OIDs

Let's break down your problem step by step:

Why does the OID 1.3.6.1.2.1.25.3.3.1.2 throw an error?

The OID 1.3.6.1.2.1.25.3.3.1.2 maps to hrProcessorLoad in the HOST-RESOURCES-MIB, which is a table-based object (it represents a collection of values, one for each CPU core/processor on the system).

Your original code uses a SNMPv1 Get request (PduType.Get), which is only designed to fetch scalar OIDs (those ending with .0, like the system info OIDs you used initially). When you try to query a table OID with a Get request, the SNMP agent (or SNMP#NET's parsing logic) throws SnmpInvalidPduTypeException because this combination is invalid for SNMPv1.

For table objects, you need to use either:

  • GetNext requests (to iterate through table entries one by one)
  • GetBulk requests (available in SNMPv2c/v3, which fetches multiple table entries at once)

How to correctly add OIDs in SNMP#NET requests

1. Adding scalar OIDs (like your original system info ones)

This is straightforward—just keep using the PduType.Get request and add the scalar OIDs (ending with .0) to the VbList as you did before:

Pdu pdu = new Pdu(PduType.Get);
// Add existing system info scalars
pdu.VbList.Add("1.3.6.1.2.1.1.1.0"); // sysDescr
pdu.VbList.Add("1.3.6.1.2.1.1.2.0"); // sysObjectID
// Add another scalar OID example
pdu.VbList.Add("1.3.6.1.2.1.25.1.1.0"); // hrSystemUptime

2. Querying table OIDs (like hrProcessorLoad)

Since you're using SNMPv1, you'll need to use GetNext requests to retrieve table entries. Here's a modified example for fetching CPU load values:

OctetString community = new OctetString("public");
AgentParameters param = new AgentParameters(community);
IpAddress agent = new SnmpSharpNet.IpAddress(ipaddress);
UdpTarget target = new UdpTarget((IPAddress)agent, 161, 2000, 1);

// Use GetNext for table OIDs
Pdu pdu = new Pdu(PduType.GetNext);
// Add the base table OID (without the index suffix)
pdu.VbList.Add("1.3.6.1.2.1.25.3.3.1.2");

SnmpV1Packet result = (SnmpV1Packet)target.Request(pdu, param);

if (result != null && result.Pdu.ErrorStatus == 0)
{
    foreach (Vb vb in result.Pdu.VbList)
    {
        Console.WriteLine($"CPU Load OID: {vb.Oid.ToString()} | Value: {vb.Value.ToString()}");
        // To get more entries, you'd send another GetNext with the last returned OID
    }
}
else
{
    Console.WriteLine($"Error: {result?.Pdu.ErrorStatus.ToString() ?? "No response"}");
}

target.Close();

If you can switch to SNMPv2c, GetBulk is more efficient for fetching multiple table entries at once:

// Switch to SNMPv2c parameters
AgentParameters param = new AgentParameters(community);
param.Version = SnmpVersion.Ver2;

Pdu pdu = new Pdu(PduType.GetBulk);
pdu.NonRepeaters = 0;
pdu.MaxRepetitions = 10; // Number of entries to fetch
pdu.VbList.Add("1.3.6.1.2.1.25.3.3.1.2");

SnmpV2Packet result = (SnmpV2Packet)target.Request(pdu, param);

if (result != null && result.Pdu.ErrorStatus == 0)
{
    foreach (Vb vb in result.Pdu.VbList)
    {
        Console.WriteLine($"CPU Load OID: {vb.Oid.ToString()} | Value: {vb.Value.ToString()}");
    }
}

Key Notes:

  • Always check if the OID you're querying is a scalar (ends with .0) or part of a table. You can confirm this using MIB browsers or OID lookup tools.
  • For SNMPv1, table queries require iterative GetNext requests. SNMPv2c/v3's GetBulk simplifies this by fetching multiple entries in one go.
  • Make sure the target Windows machine has SNMP enabled and the community string matches, and that the HOST-RESOURCES-MIB is supported (most modern Windows SNMP agents do support it).

内容的提问来源于stack exchange,提问作者B Minster

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.14 08:22:47