ActiveSocket Toolkit Add network capabilities to any Windows or .NET application

Quicklinks


ColdFusion IP to Country Sample Source Code

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.

ActiveSocket can be well integrated into ColdFusion environments. This document describes how ActiveSocket can be integrated into ColdFusion projects.

Step 1: Download and install ActiveSocket

Download ActiveSocket 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. We have first have to create the form to enter the IP or hostname and display the results.

Step 3: Create an instance of the ActiveSocket object

Before we can use the ActiveSocket toolkit to perform lookups, we have to create an instance of the IPtoCountry object. Use the following ColdFusion code to do this:

 <cfobject class="ActiveXperts.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:

<!--- Creating the activexperts IPtoCountry object --->
<cfobject class="ActiveXperts.IPtoCountry" type="com" name="objSocket" Action="Create">

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

  if(IsDefined("URL.Submitbutton")){

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

    // First query the hostname/ip-address
    objSocket.Clear();
  	objSocket.Logfile = "C:\IPToCountry_Log.txt";
  	objSocket.Host = URL.txtHostname;
	  objSocket.Query();

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

    // Fill in the default values of the form:
    strHostname = "forum.activexperts.com";
    strCountry = "";
    strCountryCode = "";
    strResult = "";
    strLastError = "";

  }
</cfscript>


<cfoutput>

<html>

<head>
  <title>ActiveSocket IP to Country Sample</title>
  <style>
    input{
      font-family: verdana;
      font-size: x-small;
      border: 1px solid black;
      width: 250px;
    }
    table{
      font-family: verdana;
      font-size: x-small;
      border: 1px solid black;
      width: 400px;
    }
  </style>
</head>

<body>

<form>
  <div align=center>
    <h2><font face=verdana>ActiveSocket IP to Country ColdFusion Sample</font></h2>
    <table>
      <tr>
        <td width=150>Hostname:</td>
        <td><input type="text" name="txtHostname" value="#strHostname#"></td>
      </tr>
      <tr>
        <td width=150>Country:</td>
        <td><input type="text" name="txtCountry" value="#strCountry#" disabled="true"></td>
      </tr>
      <tr>
        <td width=150>Country code:</td>
        <td><input type="text" name="txtCountryCode" value="#strCountryCode#" disabled="true"></td>
      </tr>
      <tr>
        <td width=150>Result:</td>
        <td><input type="text" name="txtResult" value="#strLastError#" disabled="true"></td>
      </tr>
      <tr>
        <td width=150> </td>
        <td><input type="submit" name="Submitbutton" value="Get country!" style="background-color: red; color: white;"></td>
      </tr>
    </table>
  </div>
</form>
</body>
</html>
</cfoutput>

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.