Quicklinks
ActiveSocket provides an easy-to-use development interface to a variety of IP protocols. By using ActiveSocket, you can very easily create or enhance applications with network features.
ActiveSocket features the following: DNS, FTP, HTTP, HTTPs, ICMP Ping, IP-to-Country, MSN, NTP, RSH, SCP, SFTP, SNMP v1/v2c (Get, GetNext, Set), SNMP Traps, SNMP MIB, SSH, TCP, Telnet, TFTP, UDP, Telnet, Wake-On-LAN and more.
SNMP can be well integrated into VBScript environments.
This document describes how ActiveSocket's SNMP objects can be integrated into VBScript code.
ActiveSocket is compliant with SNMP v1 and SNMP v2c. ActiveSocket automatically detects which SNMP version is running on the remote agent. Different SNMP data types, including:
The following operations are supported:
IMPORTANT: Make sure that the SNMP Service is installed and running on the machine where ActiveSocket is installed. For more details, please read FAQ items Q1200010 and Q1200015.
Download ActiveSocket from the ActiveXperts Download Site and start the installation. The installation guides you through the installation process.
Create a new script using your favorite editor. You can simply use notepad. However, a VBScript editor is recommended, so you can browse through objects, objects properties and object functions.
You're now able to write a more advanced script to communicate using the ActiveSocket Toolkit.
Create a new VBScript file called DEMO.VBS. It is recommended to insert the following line on top of your code:
Option Explicit
This statement requires that all variable names be defined (with the Dim statement), to avoid simple typos that can cause incredible headaches and long debugging sessions for something that should have never happened.
Now, declare the ActiveSocket object(s):
Dim objSnmpManager
Create the ActiveSocket object(s) like this:
Set objSnmpManager = CreateObject( "ActiveXperts.SnmpManager" )
Now, add the following lines to the file to have your fist ActiveSocket VBScript program:
WScript.Echo "Version: " & objSocket.Version WScript.Echo "Expiration Date: " & objSocket.Expiration Date
You can now query SNMP OID's.
The following VBScript code shows how to execute an SNMP query on a remote SNMP agent:
Option Explicit Dim objSnmpManager Dim objSnmpData Dim objConstants Dim strHostName, strCommunity, strValue, strOID ' Create SnmpManager and ASConstants instances Set objSnmpManager = CreateObject ( "ActiveXperts.SnmpManager" ) Set objConstants = CreateObject ( "ActiveXperts.ASConstants" ) ' Write version information and expiration date WScript.Echo "ActiveSocket " & objSnmpManager.Version & " demo." WScript.Echo "Expiration date: " & objSnmpManager.ExpirationDate & 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
There are many working samples included with the product. You can also find them on the ActiveXperts FTP site: ftp.activexperts-labs.com/samples/network-component.