Download ActiveSocket Network Communications Toolkit 4.1  (5094 KB - .exe file)
Download Manual  (505 KB - .htm file)
Send SNMP Traps using ASP
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 protocols: ICMP, HTTP and HTTPs with support for proxy servers, Telnet, NTP time protocol,
RSH remote shell script interface, SNMP (Simple Network Management Protcol), SNMP Traps, Sockets (TCP and UDP), WOL (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 ASP environments.
This document describes how ActiveSocket can be integrated into ASP 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 ActiveSocket
Download ActiveSocket from the ActiveXperts Download Site and start the installation.
The installation guides you through the installation process.
Step 2: Create a new Web Site
First, create a new directory on the IIS Server's file system. This directory will hold the ASP later on.
From the 'Start menu', click on 'Administrative Tools' and click on 'Internet Information Services (IIS) Manager'.
Right-click on the 'Web Sites' container and choose 'New->Web Site':

(Click on the picture to enlarge)
The 'Web Site Creation Wizard' is shown, guiding you thorugh the process of creating a new web site. Provide all necessary information:
- Description - a friendly description of the new site;
- IP / Port / Host Header - choose your preferred way to distinguish between other web sites on the server;
- Path - select the directory that will store the ASP file(s);
- Web Site Access Permissions - in the Web Site Access Permissions dialog, enable 'Read' and 'Run scripts (such as ASP)';
You're now able to write an ASP script to use IP protocols with ActiveSocket.
Step 3: Create the ActiveSocket object in ASP
To receive SNMP traps using ASP, 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;
Create a new ASP script called DEFAULT.ASP in the directory that was created in Step2, using your favorite editor.
On top of the ASP code, insert the following lines to declare and create the ActiveSocket objects:
<object runat=server progid="ActiveXperts.SnmpTrapManager" id=objSnmpTrapManager></object>
<object runat=server progid="ActiveXperts.SnmpTrap" id=objSnmpTrap ></object>
<object runat=server progid="ActiveXperts.SnmpObject" id=objSnmpObject ></object>
Step 4: Sending the trap
Now that we have created the objects objTrapManager, objSnmpTrap and objSnmpObject we're able to send a trap.
We need to collect the following information from the user:
- The IP address of the device we want to send the trap to;
- The name of the SNMP community;
- An objectidentifier (OID);
- The type of the data;
- The value of the data;
- The SNMP protocol version (v1 or v2c).
Please find the ASP code for sending a SNMP trap below:
<%
' Create the objects
Set objSnmpTrap = Server.CreateObject( "ActiveXperts.SnmpTrap" )
Set objSnmpObject = Server.CreateObject( "ActiveXperts.SnmpObject" )
Set objConstants = Server.CreateObject( "ActiveXperts.ASConstants" )
Set objSnmpTrapManager = Server.CreateObject( "ActiveXperts.SnmpTrapManager" )
objSnmpTrap.Clear
objSnmpObject.Clear
' Set the logfile
objSnmpTrapManager.Logfile = request("logfile")
' Initialize the SNMP Trap manager
objSnmpTrapManager.Initialize
'Set the protocol version
objSnmpTrapManager.ProtocolVersion = request("version")
' Set the SNMP data to send with the trap (variable bindings)
objSnmpObject.OID = request("oid")
objSnmpObject.Value = request("value")
select case request("oidDataType")
case "number"
objSnmpObject.Type = objConstants.asSNMP_TYPE_INTEGER32
case "text"
objSnmpObject.Type = objConstants.asSNMP_TYPE_OCTETSTRING
end select
' Set the SNMP Trap destination and community, and add the data
objSnmpTrap.Host = request ( "host" )
objSnmpTrap.Community = request ( "community" )
objSnmpTrap.AddObject objSnmpObject
'Send the trap
objSnmpTrapManager.Send objSnmpTrap
' Display the result
strResult = objSnmpTrapManager.LastError & " : " & objSnmpTrapManager.GetErrorDescription(objSnmpTrapManager.LastError)
objSnmpTrapManager.Shutdown
%>
You can download the complete sample from our ftp site ftp.activexperts-labs.com/samples/asocket.
There are many other working ActiveSocket scripts on our site and shipped with the product.
The ActiveSocket tool is a Network Communications ActiveX software component (SDK).
This control supports SNMP, SMTP, POP3, Telnet, TCP, NTP, RSH, HTTP, HTTPs, FTP, DNS, ICMP and more, and can be used by any Windows development platform,
including Visual Basic .NET, Visual CSharp .NET,
ASP .NET (VB,CS),
ASP,
Visual Basic,
Visual Studio/Visual C++,
Delphi,
PHP,
ColdFusion,
HTML,
VBScript and any other ActiveX/COM compliant platform. The ActiveSocket Toolkit is an ActiveXperts Software B.V. Product.
|