Вверх ↑
Ответов: 841
Рейтинг: 17
#1: 2012-12-04 08:29:54 ЛС | профиль | цитата
Download ActiveXperts Network Component 4.4


Option Explicit

Dim objSnmpManager
Dim objSnmpData
Dim objConstants
Dim strHostName, strCommunity, strValue, strOID

' Create SnmpManager and ASConstants instances
Set objSnmpManager = CreateObject ( "AxNetwork.SnmpManager" )
Set objConstants = CreateObject ( "AxNetwork.ASConstants" )

' Write version information and License Status
WScript.Echo "Network Component " & objSnmpManager.Version & " demo."
WScript.Echo "License Status: " & objSnmpManager.LicenseStatus & vbCrLf

' Get Host and communicaty name
Do
strHostName = inputbox( "Enter the hostname (a remote or local hostname)", "Input", "localhost" )
Loop until strHostName <> ""
Do
strCommunity = inputbox( "Enter community", "Input", "public" )
Loop until strCommunity <> ""

' Initialize SNMP
objSnmpManager.Initialize

WScript.Echo "Initialize: " & objSnmpManager.LastError & " (" & objSnmpManager.GetErrorDescription( objSnmpManager.LastError ) & ")"
WScript.Echo

If( objSnmpManager.LastError <> 0 ) Then
WScript.Quit
End If

' Open SNMP session. Pass hostname and community.
' Note: Port 161 is used. To specify a different port, pass the port number as 3rd parameter (optional)
objSnmpManager.Open strHostName, strCommunity

WScript.Echo "Open( " & strHostName & ", " & Chr(34) & strCommunity & Chr(34) & " ): " & objSnmpManager.LastError & " (" & objSnmpManager.GetErrorDescription( objSnmpManager.LastError ) & ")"
WScript.Echo

If( objSnmpManager.LastError = 0 ) Then

strOID = "system.sysDescr.0"

Set objSnmpData = objSnmpManager.Get( strOID )
WScript.Echo "Get( " & strOID & ", " & Chr(34) & strCommunity & Chr(34) & " ): " & objSnmpManager.LastError & " (" & objSnmpManager.GetErrorDescription( objSnmpManager.LastError ) & ")" & vbCrLf
If( objSnmpManager.LastError = 0 ) Then
PrintSnmpData( objSnmpData )
End If

strOID = "system.sysName.0"

Set objSnmpData = objSnmpManager.Get( strOID )
WScript.Echo "Get( " & strOID & ", " & Chr(34) & strCommunity & Chr(34) & " ): " & objSnmpManager.LastError & " (" & objSnmpManager.GetErrorDescription( objSnmpManager.LastError ) & ")" & vbCrLf
If( objSnmpManager.LastError = 0 ) Then
PrintSnmpData( objSnmpData )
End If

strOID = "system.sysUpTime.0"

Set objSnmpData = objSnmpManager.Get( strOID )
WScript.Echo "Get( " & strOID & ", " & Chr(34) & strCommunity & Chr(34) & " ): " & objSnmpManager.LastError & " (" & objSnmpManager.GetErrorDescription( objSnmpManager.LastError ) & ")" & vbCrLf
If( objSnmpManager.LastError = 0 ) Then
PrintSnmpData( objSnmpData )
End If

objSnmpManager.Close()
WScript.Echo "Close(): " & objSnmpManager.LastError & " (" & objSnmpManager.GetErrorDescription( objSnmpManager.LastError ) & ")"
WScript.Echo

End If

' Shutdown SNMP session
objSnmpManager.Shutdown
WScript.Echo "Shutdown(): " & objSnmpManager.LastError & " (" & objSnmpManager.GetErrorDescription( objSnmpManager.LastError ) & ")"
WScript.Echo

WScript.Echo "Ready."

' ********************************************************************
' Function PrintSnmpData
' ********************************************************************
Function PrintSnmpData( objSnmpData )
WScript.Echo " OID : " & objSnmpData.OID
WScript.Echo " Value : " & objSnmpData.Value
WScript.Echo " Type : " & GetTypeString( objSnmpData.Type )
WScript.Echo
End Function

' ********************************************************************
' Function GetTypeString()
' ********************************************************************
Function GetTypeString( lType )
Select Case lType
Case objConstants.asSNMP_TYPE_INTEGER32:
GetTypeString = "asSNMP_TYPE_INTEGER32"
Case objConstants.asSNMP_TYPE_BITS
GetTypeString = "asSNMP_TYPE_BITS"
Case objConstants.asSNMP_TYPE_OCTETSTRING
GetTypeString = "asSNMP_TYPE_OCTETSTRING"
Case objConstants.asSNMP_TYPE_NULL
GetTypeString = "asSNMP_TYPE_NULL"
Case objConstants.asSNMP_TYPE_OBJECTIDENTIFIER
GetTypeString = "asSNMP_TYPE_OBJECTIDENTIFIER"
Case objConstants.asSNMP_TYPE_SEQUENCE
GetTypeString = "asSNMP_TYPE_SEQUENCE"
Case objConstants.asSNMP_TYPE_IPADDRESS
GetTypeString = "asSNMP_TYPE_IPADDRESS"
Case objConstants.asSNMP_TYPE_COUNTER32
GetTypeString = "asSNMP_TYPE_COUNTER32"
Case objConstants.asSNMP_TYPE_GAUGE32
GetTypeString = "asSNMP_TYPE_GAUGE32"
Case objConstants.asSNMP_TYPE_TIMETICKS
GetTypeString = "asSNMP_TYPE_TIMETICKS"
Case objConstants.asSNMP_TYPE_OPAQUE
GetTypeString = "asSNMP_TYPE_OPAQUE"
Case objConstants.asSNMP_TYPE_COUNTER64
GetTypeString = "asSNMP_TYPE_COUNTER64"
Case objConstants.asSNMP_TYPE_UNSIGNED32
GetTypeString = "asSNMP_TYPE_UNSIGNED32"
Case Else
GetTypeString= "UNKNOWN"
End Select
End Function
карма: 0

0