Contact Info

Crumbtrail » Network Component » How to Use Network Component » IP to Country » ColdFusion

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:

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: Create an instance of the Network Component object

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="AxNetwork.Tcp" 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 activexperts IPtoCountry object --->
<cfobject class="AxNetwork.IPtoCountry" type="com" name="objSocket" Action="Create">

<!--- get the location of the IP address --->

      // Fill in the default values of the form:
    strHost = "";
    strCountryName = "";
    strCountryCode = "";
    strCountryCodeEx = "";
    strResult = "";
    strLastError = "";
    strLogfile = GetTempDirectory() & "IPToCountry.log";
    strComponent = "Module [" & objSocket.Module & "]; Build [" & objSocket.Build & "]";
     strHost = URL.txtHost;
      strCountryName = URL.txtCountryName;
     strHost = URL.txtCountryCode;
     strHost = URL.txtCountryCodeEx;
      strLogFile = URL.txtLogFile;


    // Get the hostname and strip some the prefix
    txtHost = URL.txtHost;
    txtHost = ReplaceEx(txtHost, "http://", "");
    txtHost = ReplaceEx(txtHost, "https://", "");
    txtHost = ReplaceEx(txtHost, "ftp://", "");
    // And so on..

    // First query the hostname/ip-address
  	objSocket.Logfile = strLogFile;
  	objSocket.Host = URL.txtHost;

    // If the query has succesfully executed, get
    // the results
    if(objSocket.LastError eq 0)
      strCountryName = objSocket.CountryName;
      strCountryCode = objSocket.CountryCode;
      strCountryCodeEx = objSocket.CountryCodeEx;
      strCountryName = "unknown...";
      strCountryCode = "unknown...";		
      strCountryCodeEx = "unknown...";
    // The results:
    strLastError = objSocket.LastError & ": " & objSocket.GetErrorDescription(objSocket.LastError);



  <title>ActiveXperts Network Component IP to Country Sample</title>
    text-align: center;
   font-family: verdana;
   color: navy;
   font-weight: bold;
   margin: 0px;
   font-family: verdana;
   font-size: 9pt;
   color: navy;
   border: 1px solid navy;
   background-color: white;
   width: 325px;
   font-family: verdana;
   font-size: 9pt;   
   width: 325px;
   font-family: verdana;
   font-size: 9pt;
   color: navy;
   border: 1px solid navy;
   width: 500px;
    width: 500; 
    height: 250px; 
    overflow: auto; 
    text-align: left; 
    font-size: xx-small; 
    font-family: verdana;
    border: 1px solid navy;
    font-family: verdana;
    font-size: 8pt;
    color: red;



<h2>ActiveXperts Network Component CF Sample - IP to Country</h2>
  <table class=table>
      <td><input type="text" class=input name="txtHost" value="#strHost#"></td>
      <td> </td>
      <td><input type="submit" class=button name="Submitbutton" value="Query" ></td>
      <td>Country Code:</td>
      <td><input type="text" class=input name="txtCountryCode" value="#strCountryCode#" disabled="true"></td>
      <td>Country Code Ex:</td>
      <td><input type="text" class=input name="txtCountryCodeEx" value="#strCountryCodeEx#" disabled="true"></td>
      <td>Country Name:</td>
      <td><input type="text" class=input name="txtCountryName" value="#strCountryName#" disabled="true"></td>
      <td><input type="text" class=input name="txtLogFile" value="#strLogFile#" ></td>

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



You can download the complete sample on our FTP site There are many other working Network Component scripts on our site and shipped with the product.