1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
Imports SnmpSharpNet Public Class Form1 Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load walk() End Sub Private Sub getone() Dim host As String = "MyHostName" 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 Private Sub GetBulk() Dim host As String = "MyHostName" Dim community As String = "public" Dim requestOid() As String Dim result As Dictionary(Of Oid, AsnType) Dim rootOid As Oid = New Oid("1.3.6.1.2.1.1") Dim nextOid As Oid = rootOid Dim keepGoing As Boolean = True requestOid = New String() {rootOid.ToString()} Dim snmp As SimpleSnmp = New SimpleSnmp(host, community) 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 Private Sub walk() Dim host As String = "LocalHost" Dim community As String = "public" Dim result As Dictionary(Of Oid, AsnType) Dim snmp As SimpleSnmp = New SimpleSnmp(host, community) If Not snmp.Valid Then Console.WriteLine("Invalid hostname/community.") Exit Sub End If result = snmp.Walk(SnmpVersion.Ver2, "1.3.6.1.2.1.1") 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 Class |