ActiveSocket Toolkit Add network capabilities to any Windows or .NET application

Quicklinks


Send SNMP Traps using Visual Basic 5.x/6.x

ActiveSocket provides an easy-to-use development interface (SDK) 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.

ActiveSocket is compliant with SNMP versions v1 and v2c. Several SNMP data types are supported, including:

  • ASN_INTEGER; Numeric values;
  • ASN_INTEGER32; Numeric values;
  • ASN_BITS; Bit values, for instance: one bit per port to see if a port is connected;
  • ASN_OCTETSTRING; Byte string;
  • ASN_NULL; Null value;
  • ASN_OBJECTIDENTIFIER; Object identifier (OID);
  • ASN_SEQUENCE; Text string;
  • ASN_IPADDRESS; IP address;
  • ASN_COUNTER32; 32 bit counter;
  • ASN_GAUGE32; 32 bit gauge;
  • ASN_TIMETICKS; Timestamps or uptime;
  • ASN_OPAQUE; Byte string;
  • ASN_COUNTER64; 64 bit counter;
  • ASN_UNSIGNED32; unsigned 32 bit numeric value.

ActiveSocket supports the following SNMP trap features:

  • SNMP v1 and SNMP v2c support;
  • Support for alphanumeric OID's (object identifier) and numeric OID's;
  • Multithreading architecture: send and/or receive SNMP traps simultaneously from one process using multiple threads;
  • Support for ports other than the default 161 and 162 ports;
  • Support for enterprise specific traps;
  • Support for SNMP v1 generic traps such as coldstart, warmstart, linkup, linkdown, authfailure and neighbourloss;
  • Send multiple data objects (variable bindings) using a single SNMP trap message.

ActiveSocket can be well integrated into Visual Basic environments. This document describes how ActiveSocket can be integrated into Visual Basic projects.

Prerequisites

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.

Step 1: Download and install the ActiveSocket Toolkit

Download the ActiveSocket Toolkit from the ActiveXperts Download Site and start the installation. The installation guides you through the installation process.

Step 2: Create a new Visual Basic project

Launch 'Microsoft Visual Basic' from the Start menu, and choose 'New' from the 'File Menu'. The 'New Project' dialog appears. Select 'Standard Exe' and click 'OK':

Visual Basic

(Click on the picture to enlarge)

Step 3: Refer to the ActiveSocket Library

A new Project is created, with a blank form.

First, you must add a reference to ActiveSocket in the project to be able to use the object.

To do so, choose 'References...' from the 'Project' menu. In the 'References' dialog that pops up, enable the 'ActiveSocket 3.1 Type Library' reference as shown in the following picture:

(Click on the picture to enlarge)

Click 'OK' to close the 'References...' dialog.

Step 4: Declare and create the SNMP objects

To send SNMP traps using Visual Basic, you need to declare and create the following ActiveSocket objects:

  • SnmpTrapManager; The SNMP manager which allows you to send and/or receive SNMP traps in the form of SnmpTrap objects;
  • SnmpTrap; The actual SNMP trap, this object holds some SNMP trap properties like: destination host, port and community, specific and generic trap and a timestamp;
  • SnmpObject; This object is used to hold the data to be send with the SNMP trap. These data objects are also called variable bindings.

From the Code window, select 'Form'. The Private Sub 'Form_Load()' will be displayed now. In the 'Form Load' function, create the objects in the following way:

Set objSnmpTrapManager = CreateObject("ActiveXperts.SnmpTrapManager")
Set objSnmpTrap        = CreateObject("ActiveXperts.SnmpTrap")
Set objSnmpObject      = CreateObject("ActiveXperts.SnmpObject")

Step 5: Sending a SNMP trap

When the required SNMP objects are created, you can implement the code to send a SNMP trap:

Private Sub CommandSend_Click()
    ' Declare the local SNMP objects
    Dim objSnmpTrapa  As SnmpTrap
    Dim objSnmpObject As SnmpObject
        
    ' Create the SNMP objects
    Set objSnmpTrap       = CreateObject("ActiveXperts.SnmpTrap")
    Set objSnmpObject     = CreateObject("ActiveXperts.SnmpObject")
    
    ' Set the data to be send within this trap (variable bindings)
    objSnmpObject.OID     = TextOID.Text
    objSnmpObject.Type    = GetType
    objSnmpObject.Value   = TextValue.Text
    
    ' Set the properties of the Trap object
    objSnmpTrap.Clear
    objSnmpTrap.Community = TextCommunity.Text
    objSnmpTrap.Host      = TextAgent.Text
    objSnmpTrap.Port      = CInt(TextPort.Text)

    ' Add the data to the trap
    objSnmpTrap.AddObject objSnmpObject
    
    ' Set the protocol version
    objManager.ProtocolVersion = ComboVersion.ListIndex + 1
    
    ' Send the trap
    objManager.Send objSnmpTrap
        
    ' Ready
End Sub

You can download the complete sample from our ftp site ftp.activexperts-labs.com/samples/network-component. There are many other working ActiveSocket scripts on our site and shipped with the product.