Getting Generic Errors Trying To SNMP To Cisco Switches Using SNMPSharpNET

727 Views Asked by At

I am trying to integrate into SNMP scanning with my application and have delved into Google to try and find examples, etc. I have thus come across the SNMPSharpNet DLL which has allowed me to start contacting devices using SNMP which is from this website.

However, I have two issues that are similary related:

  1. I tried to refer to this website to determine what oID to use when trying to scan a Cisco Catalyst 2960 Switch but it returned nothing (no errors and no results). The only way I could get it to work correctly (pull everything) was to use an oID of 1. This then sets off to pull back everything out of the switch, so I could then use it as a reference to determine specific oIDs for specific required data.

  2. Which leads me to my next question.... using an oID of 1 does seem to work, however, part way through it errors out with "The agent responded with an error" which doesn't really tell me anything. I get it everytime with attempting SNMP on different devices and it's not pulling back all of the data.

My code looks like this:

Sub GetNextResult()
    Dim host As String = "xx.xx.xx.xx"
    Dim community As String = "public"
    Dim requestOid() As String
    Dim result As Dictionary(Of Oid, AsnType)
    Dim rootOid As Oid = New Oid("1")
    Dim nextOid As Oid = rootOid
    Dim keepGoing As Boolean = True
    requestOid = New String() {rootOid.ToString()}
    Dim snmp As SimpleSnmp = New SimpleSnmp(host, community)
    snmp.SuppressExceptions = False
    If Not snmp.Valid Then
        Console.WriteLine("Invalid hostname/community.")
        Exit Sub
    End If
    While keepGoing
        result = snmp.GetNext(SnmpVersion.Ver1, New String() {nextOid.ToString()})
        If result IsNot Nothing Then
            Dim kvp As KeyValuePair(Of Oid, AsnType)
            For Each kvp In result
                If rootOid.IsRootOf(kvp.Key) Then
                    Console.WriteLine("{0}: ({1}) {2}", kvp.Key.ToString(), _
                                          SnmpConstants.GetTypeName(kvp.Value.Type), _
                                          kvp.Value.ToString())
                    nextOid = kvp.Key
                Else
                    keepGoing = False
                End If
            Next
        Else
            Console.WriteLine("No results received.")
            keepGoing = False
        End If
    End While
End Sub

I guess my question is: Is there some sort of reference I could refer to get a list of the different oIDs required for specific information? Or if not, can I continue to use an oID of 1 and try to fix why it continually errors out with a generic error?

Any help appreciated thanks.

1

There are 1 best solutions below

0
On

If you happen to know what is a MIB browser, use it to check out standard MIB documents, and then you see that the OID of "iso" is the root of most OIDs in use. That guarantees that your WALK operation indeed dumps out the items you want.

I don't have a Cisco Catalyst 2960 so could not exactly reproduce what you mean by "it returned nothing". Don't expect a device to implement every OIDs list in a site such as OIDVIEW, as what you should resort to is always the device manual and vendor materials.

I checked snmpsharpnet documentation and found out that your code was derived from there. Sadly Milan failed to provide a WALK function, and the code fragment listed at http://www.snmpsharpnet.com/?page_id=108 can be misleading and therefore you get your second question.

The SNMP error is expected, as GET-NEXT should hit a NoSuchName error to indicate that all available OIDs are dumped out. However, the sample code from snmpsharpnet does not tell its users that's something to be expected. The GET-BULK based WALK sample is correct, as there will be no NoSuchName error.

(Not an advertisement though) For your reference, #SNMP has its Messenger.Walk and Messenger.BulkWalk methods (looks similar) that also shows how to make WALK operations.