View Single Post
 
Old 05-26-2014, 11:11 AM
PlausiblyDamp's Avatar
PlausiblyDamp PlausiblyDamp is offline
Ultimate Contributor

Forum Leader
* Expert *
 
Join Date: Nov 2003
Location: Newport, Wales
Posts: 2,058
Default

If you are just looking at returning the SNMP information then the function would probably be something like
Code:
Public Function GetSNMP(ByVal HostAddress As String, ByVal OID As String) As Dictionary(Of Oid, AsnType)
        Dim host As String = HostAddress
        Dim community As String = "public"
        Dim requestOid() As String
        Dim result As Dictionary(Of Oid, AsnType)
        requestOid = New String() {OID}
        Dim snmp As SimpleSnmp = New SimpleSnmp(host, community)
        If Not snmp.Valid Then
            Console.WriteLine("Invalid hostname/community.")
            Exit Function
        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
        Return result

End Function
I have pretty much kept the code you included, however you probably don't need all the Console.WriteLine(...) stuff in there as that looks like it is just printing diagnostic information rather than doing anything useful.

A Dictionary (http://msdn.microsoft.com/en-us/libr...code-snippet-1) is a collection where every item has an associated key - in the case of the posted code the key would be of type Oid and the value would be of AsnType.
__________________
Intellectuals solve problems; geniuses prevent them.
-- Albert Einstein

Posting Guidelines Forum Rules Use the code tags
Reply With Quote