ActiveXperts Network Component

Quicklinks

ColdFusion DNS Client 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.


The Domain Name System (DNS) is the method by which Internet addresses in mnemonic form - such as www.activexperts.com - are converted into the equivalent numeric IP address such as 212.97.55.136. To the user and application process this translation is a service provided either by the local host or from a remote host via the Internet. The DNS server (or resolver) may communicate with other Internet DNS servers if it cannot translate the address itself. DNS names are constructed hierarchically. The highest level of the hierarchy is the last component or label of the DNS address. Labels can be up to 63 characters long and are not case sensitive. A maximum length of 255 characters is allowed. Labels must start with a letter and can only consist of letters, digits and hyphens.

Nslookup is a popular program for UNIX, Linux and Windows to query Internet domain name servers. It allows the user to query name servers for information about various hosts and domains or to print a list of hosts in a domain.


Step 1: Download and install the 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

Establishing the connection and listing the files can be done in three steps:

  • Collect the ftp-server-address, the username and the password from the user
  • Establish the connection
  • List the files

Collecting the information can be done using a form. We've made our form look like this:

(Click on the picture to enlarge)

When we've got this information, we're ready to establish a connection to a server. First of all we need an object witch creates a connection between ColdFusion and the ActiveXperts software. To do that, use the following code:

<cfobject class="ax_AxNetwork.DnsServer" type="com" name="objDns" Action="Create"> 

Once the object is created, we're able to use the component. We need to establish a connection, so we're going to use the Network Component method "connect()". Use the following code:

objDns.Connect(strHost,strUsername,strPassword);

We're displaying the results of the process using the "LastError" method of the Network Component. The method "LastError" displays a number. It's helpfull to know "0" means success. To get the error description use the "GetErrorDescription()" method. In our code we've used these methodes this way:

strResult = objDns.LastError & " : " & objDns.GetErrorDescription(objDns.LastError);

It can be very helpfull to check for errors before executing some code. Applying this can be done easily:

 if(objDns.LastError eq "0"){
    Some code
 }

Appendix: Full source code

<!--- creating the object --->
<cfobject class="ax_AxNetwork.DnsServer" type="com" name="objDnsServer" Action="Create">
<cfobject class="ax_AxNetwork.NwConstants" type="com" name="objConstants" Action="Create">

<cfoutput>
<html>
<head>
 <title>ActiveXperts Network Component DNS Sample in ColdFusion</title>
  <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: 325px; 
    height: 200px; 
    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>
</head>
<body>
</cfoutput>

<cfscript>
    strDNSServer = "ns1.interstroom.nl";
    strHost = "activexperts.com";
    strResult = "";
    strLogfile = GetTempDirectory() & "Dns.log";
    strComponent = "Module [" & objDnsServer.Module & "]; Build [" & objDnsServer.Build & "]";
    strQueryResults = "";
    
    if (isDefined("URL.txtDnsServer")){
      strDnsServer = URL.txtDnsServer;
    }     
    
    if (isDefined("URL.txtHost")){
      strHost = URL.txtHost;
    }

    if(IsDefined("URL.Submitbutton")){
      objDnsServer.Logfile = strLogfile;   
      objDnsServer.Server = strDnsServer;
      objDnsServer.Lookup(strHost, objConstants.nwDNS_TYPE_ANY);
      
      if (objDnsServer.LastError == 0){
        objDnsRecord = objDnsServer.GetFirstRecord();
        nType = objDnsRecord.Type;
        switch(nType){
          case 1: // nwDNS_TYPE_A
          {
            strQueryResults = strQueryResults & "Type             : A<br />";
            strQueryResults = strQueryResults & "Name             :" & objDnsRecord.Name & "<br />";
            strQueryResults = strQueryResults & "IPv4 Address     :" & objDnsRecord.Address & "<br />";
            break;
          }
          case 2: // nwDNS_TYPE_NS
          {
            strQueryResults = strQueryResults & "Type             : NS<br />";
            strQueryResults = strQueryResults & "Name             : " & objDnsRecord.Name & "<br />";
            strQueryResults = strQueryResults & "Name Server      : " & objDnsRecord.NameServer & "<br />";
            break;
          }
          case 5: // nwDNS_TYPE_CNAME
          {
            strQueryResults = strQueryResults & "Type             : CNAME<br />";
            strQueryResults = strQueryResults & "Name             : " & objDnsRecord.Name & "<br />";
            strQueryResults = strQueryResults & "Alias            : " & objDnsRecord.Address & "<br />";
            break;
          }
          case 6: //nwDNS_TYPE_SOA
          {
            strQueryResults = strQueryResults & "Type             : SOA<br />";
            strQueryResults = strQueryResults & "Name             : " & objDnsRecord.Name & "<br />";
            strQueryResults = strQueryResults & "Name Server      : " & objDnsRecord.NameServer & "<br />";
            strQueryResults = strQueryResults & "MailBox          : " & objDnsRecord.MailBox & "<br />";
            strQueryResults = strQueryResults & "Serial           : " & objDnsRecord.SerialNumber & "<br />";
            strQueryResults = strQueryResults & "Refresh          : " & objDnsRecord.RefreshInterval & "<br />";
            strQueryResults = strQueryResults & "Retry Interval   : " & objDnsRecord.RetryInterval & "<br />";
            strQueryResults = strQueryResults & "Expiration Limit : " & objDnsRecord.ExpirationLimit & "<br />";
            strQueryResults = strQueryResults & "Minimum TTL      : " & objDnsRecord.MinimumTTL & "<br />";
            break;
          }
          case 12: //nwDNS_TYPE_PTR
          {
            strQueryResults = strQueryResults & "Type             : PTR<br />";
            strQueryResults = strQueryResults & "Name             : " & objDnsRecord.Name & "<br />";
            strQueryResults = strQueryResults & "Host             : " & objDnsRecord.Address & "<br />";
            break;
          }
          case 15: //nwDNS_TYPE_MX
          {
            strQueryResults = strQueryResults & "Type             : MX<br />";
            strQueryResults = strQueryResults & "Name             : " & objDnsRecord.Name & "<br />";
            strQueryResults = strQueryResults & "Preference       : " & objDnsRecord.Preference & "<br />";
            strQueryResults = strQueryResults & "Mail Exchange    : " & objDnsRecord.MailExchange & "<br />";
            break;
          }
          case 28: //nwDNS_TYPE_AAAA
          {
            strQueryResults = strQueryResults & "Type             : AAAA<br />";
            strQueryResults = strQueryResults & "Name             : " & objDnsRecord.Name & "<br />";
            strQueryResults = strQueryResults & "IPv6 Address     : " & objDnsRecord.Address & "<br />";
            break;
          }
        }        
        
        strQueryResults = strQueryResults & "TTL              : " & objDnsRecord.TTL &"<br /><br />";
        
      }
      
      strResult = objDnsServer.LastError & ": " & objDnsServer.GetErrorDescription(objDnsServer.LastError);	
    }
</cfscript>



<cfoutput>

</head>
<body>
<form method=get>

<h2>ActiveXperts Network Component CF Sample - DNS</h2>

<table class=table>
 <tr>
  <td width=150>Component:</td>
  <td>#strComponent#</td>
 </tr>
  <tr>
    <td width=150>DNS Server:</td>
    <td><input class=input type=text name=txtDnsServer value="#strDnsServer#"></td>
 </tr>
 <tr>
  <td width=150>Host:</td>
  <td><input class=input type=text name=txtHost value="#strHost#"></td>
 </tr>
 <tr>
    <td> </td>
    <td><input class=button type=submit name=submitbutton value="Lookup"></td>
 </tr>
 <tr>
    <td>Logfile:</td>
    <td><input class=input type=text name=txtLogfile value="#strLogfile#"></td>
 </tr>
<tr>
  <td width=150><b>Result: </b></td>
  <td>#strResult#</td>
 </tr>
<tr>
  <td>Query results:</td>
  <td><div>#strQueryResults#</div></td>
</tr>

</table>

</form>
<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.