Shortcut Menu

Skip

Main Navigation

Choose your language


ActiveXperts Network Component Add network capabilities to any Windows or .NET application

Quicklinks


ColdFusion IP to Country 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.


This document describes how the Network Component FtpServer object can be integrated into your projects.

The most important functions of the FtpServer object are:

  • Connect - connect to the (remote) FTP server on port 21 or any alternate port;
  • Disconnect - to diconnect after a connect call;
  • GetCurrentDir - retrieve the current directory;
  • ChangeDir - change the current directory;
  • CreateDir - create a new directory;
  • RenameDir - rename a directory;
  • DeleteDir - delete a directory;
  • FindFile - find a specific file in the current directory;
  • FindFirstFile - iterate over all files in the current directory; find the first file;
  • FindNextFile - iterate over all files in the current directory; find the next file;
  • RenameFile - rename a file in the current directory;
  • DeleteFile - delete a file in the current directory;
  • GetFile - get (download) a file, either using binary transfer or ASCII transfer;
  • PutFile - put (upload) a file, either using binary transfer or ASCII transfer;

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 IPtoCountry object. Use the following ColdFusion code to do this:

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

Step 4: Perform an IP to country lookup

After creation of the IPtoCountry object, we can call its functions to perform an IP to country lookup. This can be done by just three lines of code, setting the hostname or IP address, perform the lookup and read the result.

Below you can find the sourcecode to create a simple online IP to country lookup utility:

Appendix: Full source code

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

<cfoutput>
<html>
<head>
 <title>ActiveXperts Network Component Ntp 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: 50px; 
    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>
    strTimeServer = "ntp.activexperts-labs.com";    
    strReply = "";  
    strResult = "";
    strResultCode = "";
    
    strLogfile = GetTempDirectory() & "Ntp.log";
    strComponent = "Module [" & objNtp.Module & "]; Build [" & objNtp.Build & "]";
    
    if (isDefined("URL.txtTimeServer")){
      strTimeServer = URL.txtTimeServer;
    }     
    
    if (isDefined("URL.txtLogfile")){
      strLogfile = URL.txtLogfile;
    }

    if(IsDefined("URL.Submitbutton")){
      objNtp.Logfile = strLogfile;
      objNtp.GetTime(strTimeServer);
  
      
      If (objNtp.LastError == 0){
        strReply = "Time on timeserver: " & objNtp.Year & "/" & objNtp.Month & "/" & objNtp.Day & " " & objNtp.Hour & ":" & objNtp.Minute & ":" & objNtp.Second & "<br />Difference between Time Server and Local Computer: " & objNtp.LocalOffsetSeconds & " seconds"; 
      }
      
      strResult = objNtp.LastError & ": " & objNtp.GetErrorDescription(objNtp.LastError);
	
    }
</cfscript>



<cfoutput>

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

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

<table class=table>
 <tr>
  <td width=150>Component:</td>
  <td>#strComponent#</td>
 </tr>
 <tr>
  <td width=150>Host:</td>
  <td><input class=input type=text name=txtHost value="#strTimeServer#"></td>
 </tr>
 <tr>
    <td> </td>
    <td><input class=button type=submit name=submitbutton value="Query"></td>
 </tr>
 <tr>
    <td>Logfile:</td>
    <td><input class=input type=text name=txtLogfile value="#strLogfile#"></td>
 </tr>
<tr>
  <td>Time info:</td>
  <td><div>#strReply#</div></td>
</tr>
 <tr>
  <td width=150><b>Result: </b></td>
  <td>#strResult#</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.