ActiveXperts Network Component

Quicklinks

ColdFusion SNMP Sample Source Code

Network Component provides an easy-to-use development interface to a variety of IP protocols. By using Network Component, you can very easily create or enhance applications with network features.

Network Component 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.

Network Component can be well integrated into any development platform that supports ActiveX objects.


SNMP can be well integrated into ASP .NET (Visual Basic) environments.

This document describes how Network Component's SNMP objects can be integrated into ASP .NET (Visual Basic) projects.

Network Component is compliant with SNMP v1 and SNMP v2c. Different SNMP data types are supported, 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.

Step 1: Download and install Network Component

Download Network Component from the ActiveXperts Download Site and start the installation. The installation guides you through the installation process.

Step 2: Create a new ColdFusion document

Create a new blank webdocument with the ".cfm" extention. First of all we are going to build the form whitch commands and properties of the device can be filled in. Then we are going to make a source code that connects to the device.

Step 3: Implementation

Before we can use the Network Component to perform lookups, we have to create an instance of the Rsh object. Use the following ColdFusion code to do this:

 <cfobject class="ax_AxNetwork.Snmp" type="com" name="objSocket" Action="Create"> 

Appendix: Full source code

<!--- creating the object --->
<cfobject class="ax_AxNetwork.SnmpManager" type="com" name="objSnmpManager" Action="Create">

<cfoutput>
<html>

<head>
  <style>
  <!--
  body{
    text-align: center;
  }
  h2{
   font-family: verdana;
   color: navy;
   font-weight: bold;
  }
  form{
   margin: 0px;
  }
  .input{
   font-family: verdana;
   font-size: 9pt;
   color: navy;
   border: 1px solid navy;
   background-color: white;
   width: 325px;
  }
  
  .button{
   font-family: verdana;
   font-size: 9pt;   
   width: 325px;
  }
  .table{
   font-family: verdana;
   font-size: 9pt;
   color: navy;
   border: 1px solid navy;
   width: 500px;
  }
  div{
    width: 500; 
    height: 250px; 
    overflow: auto; 
    text-align: left; 
    font-size: xx-small; 
    font-family: verdana;
    border: 1px solid navy;
  }
  a{
    font-family: verdana;
    font-size: 8pt;
    color: red;
  }
  -->
 </style>
</cfoutput>
<cfscript>

getvars();

if(IsDefined("URL.getnext") eq "true"){
   snmpget("getnext", strOid);
}
else{
	 snmpget("dontgetnext", strOid);
}


function getvars(){

    strOid = "system.sysName.0";
    strHost = "localhost";
    strCommunity = "public";
    strPort = 161;
    strVersion = 2;
    strLogfile = GetTempDirectory() & "Snmp.log";
    strComponent = "Module [" & objSnmpManager.Module & "]; Build [" & objSnmpManager.Build & "]";
    strValue = "";
		
    if(IsDefined("URL.oid")){
     if(URL.oid neq ""){
		  strOid = URL.oid;
		 }
		}
    if(IsDefined("URL.host")){
     if(URL.host neq ""){
      strHost = URL.host;
     }
    }
    if(IsDefined("URL.community")){
     if(URL.community neq ""){
      strCommunity = URL.community;
     }
    }
    if(IsDefined("URL.port")){
     if(URL.port neq ""){
      strPort = URL.port;
     }
    }
    if(IsDefined("URL.version")){
     if(URL.version neq ""){
      strVersion = URL.version;
		 }
    }
    if(IsDefined("URL.logfile")){
     if(URL.logfile neq ""){
      strLogFile = URL.logfile;
     }
    }

}

function snmpget(getnext, OID){

   objSnmpManager.LogFile = strLogFile;
   objSnmpManager.Initialize();
   objSnmpManager.ProtocolVersion = strVersion;
   
   if(objSnmpManager.LastError eq 0){
      objSnmpManager.Open(strHost,strCommunity,strPort);
   }

   if(objSnmpManager.LastError eq 0){
     objSnmpObject = objSnmpManager.get(OID);
     if (getnext eq "getnext") {
       objSnmpObject = objSnmpManager.getnext();
     }
	   
     }
	 
     if(objSnmpManager.LastError eq 0){

     strOid = objSnmpObject.oid;
     strValue = objSnmpObject.value & "<br>";
		 
     }

     strResult = objSnmpManager.LastError & ": " & objSnmpManager.GetErrorDescription(objSnmpManager.LastError);
	 
     objSnmpManager.Close();
     objSnmpManager.Shutdown();	 
}

</cfscript>

<cfoutput>

</head>

<body>

<h2>ActiveXperts Network Component CF Sample - SNMP</h2>
<form>
<table class="ax_table">
  <tr>
    <td width=150>Component:</td>
    <td>#strComponent#</td>
  </tr>
 <tr>
  <td width=150>Host:</td>
  <td><input class="ax_input" type=text name=host value="#strHost#"></td>
 </tr>
 <tr>
  <td>Community:</td>
	<td><input class="ax_input" type=text name=community value="#strCommunity#"></td>
 </tr>
 <tr>
  <td>Port:</td>
	<td><input class="ax_input" type=text name=port value="#strPort#"></td>
 </tr>
 <tr>
  <td>Version:</td>
	<td>
	 <cfif strVersion eq 2>
   <select name=version class="ax_input">
    <option value="2">Snmp v2 (default)</option>
    <option value="1">Snmp v1</option>
   </select>
	 <cfelse>
   <select name=version class="ax_input">
    <option value="1">Snmp v1</option>
    <option value="2">Snmp v2 (default)</option>		
   </select>	 
	 </cfif>
	</td>
 </tr> 
 <tr>
  <td>OID:</td>
	<td><input class="ax_input" type=text name=oid value="#strOid#"></td>
 </tr>
 <tr>
  <td>Logfile:</td>
	<td><input class="ax_input" type=text name=logfile value="#strLogfile#"></td>
 </tr>
 <tr>
  <td> </td>
	<td><input class="ax_button" type=submit value="Get"></form></td>
 </tr>
 <tr>
  <td> </td>
	<td>
   <form>
    <input type=hidden name=oid value="#strOid#">
		<input type=hidden name=host value="#strHost#">
		<input type=hidden name=community value="#strCommunity#">
		<input type=hidden name=port value="#strPort#">
		<input type=hidden name=logfile value="#strLogfile#">
		<input type=hidden name=Version value="#strVersion#">
		<input type=hidden name=getnext value="true">					
		<input type=submit value="Get next!" class=button>
   </form>
	</td>
 </tr>
</table>

<br>

<table class=table>
  <tr>
	  <td><b>#strOid#:</b><br>#strValue#</td>
	</tr>
</table>

<br>

<table class=table>
  <tr>
	  <td width=150><b>Result:</b></td><td>#strResult#</td>
	</tr>
</table>

<br>

<p>This sample is based on ActiveXperts Network Component, an <a target="blank" href="http://www.activexperts.com">ActiveXperts Software</a> product.</p>
<a href="index.cfm">Back to main page</a>

</body>
</html>

</cfoutput>

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