Grazie a questa libreria sono riuscito a catturare i contatori della mia Multifunzione PANASONIC KX-MB2061, lo scopo del progetto è quello di calcolare quanto consumo e spendo per la mia multifunzione.
Per prima cosa dobbiamo importare la libreria SNMP nel progetto di vb.net, per aiutarvi vi posto l'intero codice :
Imports System
Imports SnmpSharpNet
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim str(8) As String
For i = 0 To 8
str(i) = "1.3.6.1.4.1.258.402.1.4.2.1.7." & i + 1
Next i
Dim RIS(8) As String
Dim val_ris(8) As String
RIS = Carica_Dati("192.168.1.191", str)
val_ris = Carica_Val()
For i = 0 To 8
Debug.Print(val_ris(i) + " : " + RIS(i))
Next i
'Controllo()
End
End Sub
Private Function Carica_Val() As String()
Dim TESTO(8) As String
TESTO(0) = "Total Print Page"
TESTO(1) = "OPC Drum Count"
TESTO(2) = "FB Scan Page"
TESTO(3) = "ADF Scan Page"
TESTO(4) = "Copy Page"
TESTO(5) = "PC Print Page"
TESTO(6) = "PC Scan Page"
TESTO(7) = "Fax Send Page"
TESTO(8) = "Fax Receive Page"
Return TESTO
End Function
Private Sub Controllo()
Dim host As String = "192.168.1.191"
Dim community As String = "public"
Dim requestOid() As String
Dim result As Dictionary(Of Oid, AsnType)
'Tempo acesa macchina "1.3.6.1.2.1.1.3.0"
'Panasonic
'Total Print Page /OID: .1.3.6.1.4.1.258.402.1.4.2.1.7.1; Value (Integer):
'OPC Drum Count /OID: .1.3.6.1.4.1.258.402.1.4.2.1.7.2; Value (Integer):
'FB Scan Page /OID: .1.3.6.1.4.1.258.402.1.4.2.1.7.3; Value (Integer):
'ADF Scan Page /OID: .1.3.6.1.4.1.258.402.1.4.2.1.7.4; Value (Integer):
'Copy Page /OID: .1.3.6.1.4.1.258.402.1.4.2.1.7.5; Value (Integer):
'PC Print Page /OID: .1.3.6.1.4.1.258.402.1.4.2.1.7.6; Value (Integer):
'PC Scan Page /OID: .1.3.6.1.4.1.258.402.1.4.2.1.7.7; Value (Integer):
'Fax Send Page /OID: .1.3.6.1.4.1.258.402.1.4.2.1.7.8; Value (Integer):
'Fax Receive Page /OID: .1.3.6.1.4.1.258.402.1.4.2.1.7.9; Value (Integer):
requestOid = New String() {"1.3.6.1.2.1.1.1.0", "1.3.6.1.2.1.1.5.0", "1.3.6.1.4.1.258.402.1.4.2.1.7.1", "1.3.6.1.4.1.258.402.1.4.2.1.7.2"}
Dim snmp As SimpleSnmp = New SimpleSnmp(host, community)
If Not snmp.Valid Then
' Console.WriteLine("Invalid hostname/community.")
Debug.Print("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())
Debug.Print("{0}: ({1}) {2}", kvp.Key.ToString(), _
SnmpConstants.GetTypeName(kvp.Value.Type), _
kvp.Value.ToString())
Next
Else
' Console.WriteLine("No results received.")
Debug.Print("No results received.")
End If
End Sub
Private Function Carica_Dati(ByVal IP As String, ByVal Valore() As String) As String()
Dim risultato(8) As String
Dim host As String = IP
Dim community As String = "public"
Dim result As Dictionary(Of Oid, AsnType)
'Tempo acesa macchina "1.3.6.1.2.1.1.3.0"
Dim snmp As SimpleSnmp = New SimpleSnmp(host, community)
If Not snmp.Valid Then
risultato(0) = "Errore"
Return risultato
End If
result = snmp.Get(SnmpVersion.Ver1, Valore)
If result IsNot Nothing Then
Dim kvp As KeyValuePair(Of Oid, AsnType)
Dim n As Integer
n = 0
For Each kvp In result
risultato(n) = kvp.Value.ToString()
n = n + 1
Next
Else
' Console.WriteLine("No results received.")
Debug.Print("No results received.")
End If
Return risultato
End Function
End Class
Spero che vi può essere utile il mio piccolo contributo.