ActiveSocket

 Product Overview

 ActiveSocket Objects:
 
 How to use

 Online Samples

 Download (.exe)

 Brochure (.pdf)

 Manual (.htm)

 Release Notes


Support

 Knowledge Base

 Forum

 Contact Support


Purchase

 Licensing

 Pricing

 Order now


Related documents

 Tutorials

 Tools


  Download ActiveSocket Network Communications Toolkit 4.1  (5094 KB - .exe file)
  Download Manual  (505 KB - .htm file)


ASP 2.x SNMP Sample Source Code


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: ICMP, HTTP and HTTPs with support for proxy servers and secure web sites, Telnet, NTP time protocol, RSH remote shell script interface, SNMP (Simple Network Management Protcol), SNMP Traps, Sockets, WOL (Wake-On-LAN), and more.

SNMP can be well integrated into ASP environments.
This document describes how ActiveSocket's SNMP objects can be integrated into ASP projects.

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:
  • String types (also called "octet strings");
  • Integer types (16bit, 32bit, 64bit and unsigned integers);
  • IP Address types;
  • Timetick types;
  • Counter types (32bit and 64bit counters);
  • OID types (also called "Object ID's");
  • Other, less frequently used datatypes.
The following operations are supported:
  • Get - retrieve an object variable from the (remote) agent;
  • GetNext - retrieve the next object variable from a table or list within an agent;
  • Set - set values for object variables within an agent.


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

Create a new ASP script called index.asp in the directory that was created in Step2, using your favorite editor. To be able to communicate with ActiveSocket we need to create an object. The following lines are used to declare and create the ActiveSocket object:
   Set objSocket = Server.CreateObject( "ActiveXperts.SnmpManager" )


Step 4: Create the form

First of all we need to get some information from the client. Like witch protocol we want to use, what command is goint to be sent, and so on. We're using the form displayed in the image below for that. This is a simple html form witch calls to itself (index.asp) to execute some commands. You can find further explination about that below.

    
    (Click on the picture to enlarge)

The HTML code to create this form is shipped with our product. You can also download it from our ftp server even as many other working SNMP examples.


Step 5: Sessions

Because we're going to make a form that can send an OID and also is going to be able to get the next OID, it is nessecairy to refresh the page a couple of times. While we're doing this we dont want to lose crucial information like the server we want to query or the last OID. Thats why we are using session variables in this sample.

Session("Sessionvar")


Step 6: Executing the commands in ASP

Now that we have the ActiveSocket object included, created the session variables and a form, we're able to get some commands executed.

First of all we need to create a sub that opens the ActiveSocket device. I'm using the following code for that:
sub openSocket

  on error resume next

  'first of all we're going to open the ActiveXperts SnmpManger so we can send OID's
  Set objSocket = Server.CreateObject( "ActiveXperts.SnmpManager" )

  objSocket.LogFile = Session("logfile")

 'initialise SNMP
  objSocket.Initialize
            		
 'set version
  objSocket.ProtocolVersion = Session("sesVersion")
	        		
 'open the object
  objSocket.open Session("sesServer"), Session("sesCommunity")

end sub


Now we need a script to close the device:
sub closeSocket

   'display the errors:
   strError = objSocket.lasterror & " : " & objSocket.geterrordescription(objSocket.lasterror)

  'close the object
   objSocket.close
   objSocket.shutdown
   objSocket.clear

end sub


Now that we are able to open and to close the ActiveSocket SNMP Manager, we can execute the commands given in the form. First the code for just executing a command:

if request("submitbutton") <> "" then

  on error resume next

  'put everything in a session variable so when you hit the get next link, you're settings won't get lost
  Session( "sesVersion" ) = request( "version" )
  Session( "sesOid" ) = request( "oid" )
  Session( "sesHost" ) = request( "server" )
  Session( "sesCommunity" ) = request( "community" )
  Session( "sesLogfile" ) = request( "logfile" )

  'open ActiveSocket toolkit
  openSocket

  'print the OID results
  if objSocket.lasterror = 0 then
	set objSnmpData = objSocket.Get(Session("sesOid"))
    strResult = objSnmpData.Value
  else
    strError = response.write("Failed: " & objSocket.lasterror & response.write(objSocket.geterrordescription(objSocket.lasterror)))
  end if

  
  closeSocket

else
    
  'do nothing

end if


And we can also get the next command:
if request("getnextbutton") <> "" then

  on error resume next

  openSocket

 'print the results
  if objSocket.lasterror = 0 then
	set objSnmpData = objSocket.Get(Session("sesOid"))
	set objSnmpData = objSocket.GetNext()
    Session("sesOid") = objSnmpData.OID
	strResult = objSnmpData.Value
  else
    strError = response.write("Failed: " & objSocket.lasterror & response.write(objSocket.geterrordescription(objSocket.lasterror)))
  end if
  
  closeSocket

else
    
  'do nothing

end if


The results are stored in a variable that is previewed in a table:

<b>:Value:</b>
<table>
 <tr>
  <td><% = strResult %> </td>
 </tr>
</table>

<br>
<b>Completion Code:</b>
<table>
 <tr>
  <td><% = strError %></td>
 </tr>
</table>

There are many working samples included with the product. You can also find them on the ActiveXperts FTP site: ftp.activexperts-labs.com/samples/asocket.





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.

Copyright ©1999-2007 ActiveXperts Software. All rights reserved.