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 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:
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.
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:
You're now able to write an ASP script to use IP protocols with ActiveSocket.
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" )
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.
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")
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/network-component.