0

我正在基于此示例编写一个简单的应用程序: https ://snmpsharpnet.com/index.php/simplesnmp-with-vb-net/

在那里你可以看到如何获得两个不同的 OID 值:

Imports System
Imports SnmpSharpNet
Module Module1
    Sub Main()
        Dim host As String = "localhost"
        Dim community As String = "public"
        Dim requestOid() As String
        Dim result As Dictionary(Of Oid, AsnType)
        requestOid = New String() {"1.3.6.1.2.1.1.1.0", "1.3.6.1.2.1.1.2.0"}
        Dim snmp As SimpleSnmp = New SimpleSnmp(host, community)
        If Not snmp.Valid Then
            Console.WriteLine("Invalid hostname/community.")
            Exit Sub
        End If
        result = snmp.Get(SnmpVersion.Ver1, requestOid)
        If result IsNot Nothing Then
            Dim kvp As KeyValuePair(Of Oid, AsnType)
            For Each kvp In result
                Console.WriteLine("{0}: ({1}) {2}", kvp.Key.ToString(), _
                                  SnmpConstants.GetTypeName(kvp.Value.Type), _
                                  kvp.Value.ToString())
            Next
        Else
            Console.WriteLine("No results received.")
        End If
    End Sub
End Module

但是在我的测试中,我注意到如果设备没有回复其中一个 OID(例如,对于我所质疑的设备无效),即使另一个 OID 有效,“结果”也是“无”(并且有一个有效的响应)。这是正常的吗?我应该打开一个新连接并查询每个 OID 以从有效 OID 中获取所有答案吗?

4

0 回答 0