Edinburgh Web Development

Are IP addresses geographic?

by Iain Wilson

12 April 2011

We recently had a query about using the IP address of web visitors to determine their geographic location and work out which services they would be allowed to use on the website. Will this work? The short answer is yes, but only up to a point and probably should only be used for non-critical purposes.

First of all there really isn't any connection between an IP address and the geographic location. The numbers are allocated arbitrarily, so you could have two very similar numbers for places that were on the opposite side of the world.

So how do you find out the location from an IP address? The techies would probably want to do a reverse DNS lookup to find the domain name associated with the address, then check the Whois record for the domain to locate the country of the registrant - but this would be complicated and take a long time and be subject to failure, so it's not really a great option.

A better way might be to use one of the databases around that purport to be able to reconcile the IP address to a location. Some of them charge for the service but there are free ones. I have heard that the chargeable ones are quite good - Google uses a 3rd party geo-database for their visitor location map in Analytics. How good the quality of the free ones is I don't know but it would be relatively easy to try one out. Response speed would also be important if a page serve depended on prior retrieval of the location.

However there is also a fundamental problem, even using a great geo-database. The IP address and it's geographic location may depend on the address of the ISP that the web visitor is connected to so the granularity of the result may be a little coarse. By this I mean, although I might physically be in Edinburgh, Scotland, my ISP might be based in London, so I may well show up as being in London. Also the country codes are usually ISO codes, so anyone in Scotland, England, N Ireland and Wales would just show up as being in the UK.

You also have situations where the IP address of a web visitor is withheld or changed by the use of anonymous proxy servers for all sorts of reasons, so there would be situations where the IP address wasn't available to the programming language or was downright wrong.

So the best advice is probably to leave well alone unless your requirement is non-critical and can survive getting the location wrong a few times!

Liked this article? Please share it with your friends and colleagues.


comments powered by Disqus
 
Blot Design,
10 Colinton Road, Edinburgh, EH10 5DT
Terms, Cookies & Privacy