KB_Soft Group - Software Vendor's Development Partner
Start page
Site map
Contacts
   

 

   

Introduction

It is often necessary to get information about a user or a site by their IP address. For example, such a need appears at the determination of a site's target audience. Having received the data about site users it is possible to promote the site more effectively and develop different marketing actions. There are quite a lot commercial services provided such information. Choice of such systems is often determined by the volume of information received, by its accuracy and importance and also by simplicity of adjusting and getting of information. The purpose of this article is to show techniques of getting information about a user or a site by their IP address, and demonstrate an example of developing of a demo


  application enabling to get this information quickly and simply. There is a simplified class source code in the form of DLL-library presenting all main functions for getting information by IP address, and a code of a demo application using this class are presented in the attached to the article archive. You can use this code with research aims in your desktop or web-applications for getting information about site users or with an aim to get information about some site (it is enough to know this site's IP address). This article is based on the experience of KBSoft, and information received from the documentation of IP addresses analyzing systems studied in this article.



   

Review of services for getting information by IP Address

    A lot of companies provide services on getting information by IP address. Some of them, providing free demo services are described in this article. One of them is CDYNE. This company presents web-service under the name IP2Geo, which returns information in the form of XML by IP address. This web-service is convenient, and there were noticed no restrictions for a test getting of information. But there are disadvantages as well: the service provides not a large quantity of information and the accuracy of location definition is not very high.

Also the company IP2Location provides similar services. The company's site provides more information than CDYNE service, but the demo page restricts quantity of requests not more than 20 per day and presents results in an inconvenient for processing form.

The company FraudLabs also uses IP2Location data base. Advantages and disadvantages coincide with those of the previous company with an exception of the fact that the demo page

  returns the result in the XML form, which significantly simplifies the processing of this data. And with the help of demo pages it is possible to get much more information, that from the previous company.

The most convenient services, to the author's point of view, are those provided by the company GeoBytes. Their advantage is a big volume of useful information, there is a possibility to get reply from server in XML form, and also more acceptable restrictions of the trial-version (not more than 20 requests per hour). Besides, for getting information in different formats there is a possibility to use different templates, which can present information in a desirable view. Unfortunately, disadvantages also exist here: requests are sent via HTTP GET, but not via web-service (it is under development now), which influences the security of the sent confidential data not in the best form (in case you bought a paid access). Moreover, in case of a use of paid access for getting information is complicated due to the need to use session token.


   

Why a probability to get wrong information exists?

    The most useful information that can be received by IP address is the user's location. It is only necessary to get information about the latitude and the longitude for that and the rest information needed to make different reports (for example, monetary units, time zone etc.) can be received knowing these characteristics. But it's not that simple to do as it seems at first site. The thing is, that IP address is not assigned with some certain geographical location (for example IP addresses of subnets are absolutely useless for determination of a geographical location), that is why it is impossible to get information about the location of the IP address possessor with an


  absolute accuracy. Furthermore, there are proxy-servers and NAT, which have opaque structure and that is why it is impossible to receive location of an IP address using proxy-server or NAT. What can be maximally received is location of the proxy-server or NAT itself. Moreover, there are proxy-servers, which generate random IP addresses or use header HTTP_X_FORWARDED_FOR. IP address from mobile phones or satellite systems will distinguish themselves with a most inaccurate location. Nevertheless, in the majority of cases location of IP addresses possessors can be precisely determined or you can track a cell phone with our cell phone spy software.


   

Program code description

The designed class KBS_IPLocatorClass provedes opportunities on the request of information from two sites: CDYNE and Geobytes. There is a possibility to request information as about your own IP address and about any other IP address entered in the request field. Besides, the class presents a possibility to parse the received XML data. Along with XML-template Geobytes presents other templates providing the achievement of other aims as well (see here). The most useful template is valuepairsAll.txt, because this

  template presents most complete information, but, unfortunately, there can occur problems at the parsing of data received. Nevertheless, having developed a function on parsing and having added it into the class source code you can easily add a possibility on processing of any template and get information you are interested in with the help of class LookupCustomIP(). Besides, the class flexible architecture enables to add a request and processing of information from any site presenting such information.

    Here is the LookupCustomIP() method code:
public bool LookupCustomIP(string ipAddress, ServerTypes serverType)
{
    try
    {
        //create the request URL
        string requestURL="";
        //add the host element of the URL
        switch (serverType)
        {
            case ServerTypes.Geobytes:
                requestURL = 
                "http://www.geobytes.com/IpLocator.htm?GetLocation&template="
                + strTemplateFileName + "&IpAddress=" + ipAddress;
                break;
            case ServerTypes.Cdyne:
                requestURL = 
                "http://ws.cdyne.com/ip2geo/ip2geo.asmx/ResolveIP?ipAddress="
                + ipAddress + "&licenseKey=0";
                break;
        }
        
        // create the web client and obtain the response data
        // as a byte array
        WebClient webclient = new WebClient();
        byte[] response = webclient.DownloadData(requestURL.ToString());
        // process the XML result to obtain a validation result
        return processXMLResult(response);

    }
    catch (Exception)
    {
        return false;
    }
}
    Besides, you can get to know your real IP address by which you will be identified in the global network with the help of the demo application. The class also presents a possibility to check the validity of the entered IP. The source code, containing only basic functions necessary for

  getting information by IP is attached to the article. In real developed by KBSoft projects a class with wider opportunities which doesn't use free services and allows to collect information about visitors of the developed sites and make different reports was used.


   

Use of the Source Code

There is a simplified class source code in the form of DLL-library presenting all main functions for getting information by IP address, and a code of a demo application using this class are presented in the attached to the article archive. You can use this code in your program products (sites) with research aims, in order to receive information by IP address or just use the demo application for getting information about singular IP addresses. In order to use the source code attached to the article it is necessary that .Net Framework 2.0 or higher was installed in the system, and the library

  KBS_IPLocatorClass.dll was in the same folder as the executed file. If you have Visual Studio 2005, you can run the demo application by opening KBS_IPLocatorDemo.sln solution and and executing the code. Or you can simple start the executed file KBS_IPLocatorDemo.exe. As Geobytes puts a restriction on the quantity of requests per hour (not more than 20), then if you exhausted this limit, you can get information via CDYNE, but in this case the information will be less detailed.


    The demo application presents the following data:

Table 1 - Main parameters of the responce
Parameter Description
IP This field presents IP address for which the request was sent.
Country ID this field is an internal key used to relate a specific row in DB table to related rows in the Regions, Cities, and Dmas tables. This is the primary key and is unique. The number "113" for example is the key for India.
Country this field is a string representation of the country name, for example, "India", "Singapore" or "Canada".
FIPS FIPS104 or more precisely FIPS 10-4 is a publication by the Federal Information Processing Standards body that identifies geopolitical entities around the world with a code. For example, "AS07" is the state of Victoria in Australia. This field represents logical groupings of these four letter codes, so in this example the letters "AS" would be stored in the "FIPS104" field. More information about this publication can be found at the National Imagery and Mapping Agency at this page and this page .
ISO 2 this field represents the "A 2" column in the ISO 3166 document which lists each country with associated alpha and numeric codes. More information on ISO 3166 standard can be found at the International Organization for Standardization web-site at this page. An example is "US" which represents the United States of America.
ISO 3 this field represents the "A 3" column in the ISO 3166 document which lists each country with associated alpha and numeric codes. More information on ISO 3166 standard can be found at the International Organization for Standardization web-site at this page. An example is "GTM" which represents Guatemala.
ISO N this field represents the "Number" column in the ISO 3166 document which lists each country with associated alpha and numeric codes. More information on the ISO 3166 standard can be found at the International Organization for Standardization web-site at this page. An example is "036" which represents Australia.
Internet this field represents the "ccTLD" code designated by IANA (Internet Assigned Numbers Authority) which is employed in the DNS to identify hosts in various countries around the world. For example, the code "uk" is assigned to the United Kingdom. The "ccTLD" codes are based on the "A 2" column of the ISO 3166 standard document. More information on the Internet Assigned Numbers Authority can be found at this page, more information on the International Organization for Standardization can be found at this page.
Comment this field represents the comments
Region ID this field is an internal key used to relate a specific row in DB table to related rows in the "Cities" table.
Region this field is the character representation of the sub-country geographical region. For example, the value of this column might be the state "Florida" in the USA or "New South Wales" in Australia.
Code this field is a 2 character code used to represent the general abbreviation for a sub-country geographical region. Each region has a unique code within a given country, and existing official codes were used where possible. "Official" can mean various things, but the ISO 3166-2 codes have been favored at this page. The codes are mnemonic. They consist of the first letter in the subdivision name, followed by a letter that occurs later in that name, unless it was impossible to assign unique codes by that rule.
ADM this field is related to the "FIPS104" field in the "Countries" table. Where the "FIPS104" code is used to identify a geopolitical region at country resolution, the "ADM1Code" is used to identify a geopolitical region at a sub-country region. For more information on the "ADM1Code" field visit the National Imagery and Mapping Agency Internet site at this page.
City ID this field is an internal key used to relate a specific rows in DB table to related rows in the "Subnets" and "NearbyCities" table. This is the primary key and is unique. The number "1225" for example is the key for Melbourne, Australia.
City this field is a character representation of the actual name of the city. For example "New York", "London" or "Paris". This field should not be used as the key for queries since the names of cities are not globally unique.
Latitude this field is used to store the approximate latitude of the city specified by the rest of the row.
Longitude this field is used to store the approximate longitude of the city specified by the rest of the row.
Time Zone this field is used to indicate which time zone the city is in. For example, the "TimeZone" field value for Sydney, Australia is "+10:00" being UTC (or GMT) plus 10 hours. The time is represented in UTC (Coordinated Universal Time). UTC was formerly known as GMT (Greenwich Mean Time). See ISO8601:2000(E) for further information on time zone representation. The ISO is available in this PDF-file
DMA this is the DMA code as assigned by Nielsen Media - http://www.nielsenmedia.com Designated Market Areas (DMA's) are used by Nielsen Media Research to identify TV stations whose broadcast signals reach a specific area and attract the most viewers. A DMA consists of all counties whose largest viewing share is given to stations of that same market area. Non-overlapping DMA's cover the entire continental United States, Hawaii and parts of Alaska. There are currently 210 Designated Market Areas throughout the U.S.
DMA ID this field is an internal key used to relate a specific rows in DB table
Market this field represents the market area
Certainty this field is used to list the certainty for the information contained in the DB in relation to the subnet being searched on and the city that it is related to. A lower certainty rating may indicate that the data gathered was inconclusive or that the particular subnet serves a greater geographical area.
Location Code this field is a 4 character alpha code used to represent a city within a given country and region. The code consists of the first letter of each word, then followed by the next 2 characters in the last word. If the city has only one word, then the first 4 characters would be used. When generating these codes if there was a duplicate code generated, then the next letter in the city name would be used. If a duplicate code is still found, then the last character of the code is replaced by a letter from the alphabet in descending order.
IP Address this field is the IP address that used to perform the resolution. It is useful to use this field to pass in a selected IP address for use with testing.
Area Code this field represents the area code
State Province this field represents the information about state province

Conclusion

In the article various techniques of getting information by IP Address were demonstrated and a source code of the created class in the form of DLL-library presenting main functions of getting information by IP address, and also a demo application using this class were shown.

References

  • This is a demo page of the company CDYNE for getting information by IP Address.
  • This is a demo page of the company IP2Location for getting information by IP Address.
  • This page contains the set of demo pages of the company FraudLabs for getting information by IP Address
  • This is a demo page of the company Geobytes for getting information by IP Address.