Geolocation by IP Address

By Andrew Turner on Mon, 2004-10-25 01:00. Webmaster

Determining geographic locations based on Internet IP offers localization services and brings together user communities without the need for GPS receivers or complicated configuration switching.

The Internet has become a collection of resources meant to appeal to a large general audience. Although this multitude of information has been a great boon, it also has diluted the importance of geographically localized information. Offering the ability for Internet users to garner information based on geographic location can decrease search times and increase visibility of local establishments. Similarly, user communities and chat-rooms can be enhanced through knowing the locations (and therefore, local times, weather conditions and news events) of their members as they roam the globe. It is possible to provide user services in applications and Web sites without the need for users to carry GPS receivers or even to know where they themselves are.

Geolocation by IP address is the technique of determining a user’s geographic latitude, longitude and, by inference, city, region and nation by comparing the user’s public Internet IP address with known locations of other electronically neighboring servers and routers. This article presents some of the reasons for and benefits of using geolocation through IP address, as well as several techniques for applying this technology to an application, Web site or user community.

Why Geolocation?

The benefits of geolocation may sound complex, but a simple example may help illustrate the possibilities. Consider a traveling businessman currently on the road to San Francisco. After checking into his hotel, he pulls out his laptop and hops onto the wireless Internet access point provided by the hotel. He opens his chat program as well as a Web browser. His friends and family see from his chat profile that he currently is near Golden Gate Park. Consequently, they can determine his local time. By pulling up a Web browser, furthermore, the businessman can do a localized search to find nearby restaurants and theaters.

Without having to know the address of the hotel he’s staying in, the chat program and Web pages can determine his location based on the Internet address through which he is connecting. The following week, when he has returned to his home in Florida, he uses his laptop to log into a chat program, and his chat profile correctly places him in his home city. There is no need to change computer configurations, remember addresses or even be aware, as the user, that you are benefitting from geolocation services.

Possible applications for geolocation by IP address exist for Weblogs, chat programs, user communities, forums, distributed computing environments, security, urban mapping and network robustness. We encourage you to find out what applications and Web sites currently employ geolocation or could be enhanced by adding support.

Although several methods of geographically locating an individual currently exist, each system has cost and other detriments that make them technology prohibitive in computing environments. GPS is limited by line-of-sight to the constellation of satellites in Earth’s orbit, which severely limits locating systems in cities, due to high buildings, and indoors, due to complete overhead blockage. Several projects have been started to install sensors or to use broadcast television signals (see Resources) to provide for urban and indoor geolocation. Unfortunately, these solutions require much money to cover installation of new infrastructure and devices, and these services are not supported widely yet.

By contrast, these environments already are witnessing a growing trend of installing wireless access points (AP). Airports, cafes, offices and city neighborhoods all have begun installing wireless APs to provide Internet access to wireless devices. Using this available and symbiotic infrastructure, geolocation by IP address can be implemented immediately.

Geolocation Standards and Services

As discussed below, several RFC proposals have been made by the Internet Engineering Task Force (IETF) that aim to provide geolocation resources and infrastructure. However, these standards have met with little support from users and administrators. To date, there has not been much interest in providing user location tracking and automatic localization services. Several companies now offer pay-per-use services for determining location by IP. These services can be expensive, however, and don’t necessarily offer the kind of functionality a programmer may want when designing his or her Web site or application.

Several years ago, CAIDA, the Cooperative Association for Internet Data Analysis, began a geolocation by IP address effort called NetGeo. This system was a publicly accessible database of geographically located IP addresses. Through the use of many complex rules, the NetGeo database slowly filled and was corrected for the location of IP addresses. The project has been stopped, however, and the technology was licensed to new partners. However, the database still is available, although several years old, and provides a good resource for determining rough locations.

To query the NetGeo database, an HTTP request is made with the query IP address, like this:

--
$ http://netgeo.caida.org/perl/netgeo.cgi?target=192.168.0.1 
VERSION=1.0
TARGET: 192.168.0.1
NAME: IANA-CBLK1
NUMBER: 192.168.0.0 - 192.168.255.255
CITY: MARINA DEL REY
STATE: CALIFORNIA
COUNTRY: US
LAT: 33.98
LONG: -118.45
LAT_LONG_GRAN: City
LAST_UPDATED: 16-May-2001
NIC: ARIN
LOOKUP_TYPE: Block Allocation
RATING: 
DOMAIN_GUESS: iana.org
STATUS: OK
--

As you can see, the NetGeo response includes the city, state, country, latitude and longitude of the IP address in question. Furthermore, the granularity (LAT_LONG_GRAN) also is estimated to give some idea about the accuracy of the location. This accuracy also can be deduced from the LAST_UPDATED field. Obviously, the older the update, the more likely it is that the location has changed. This is true especially for IP addresses assigned to residential customers, as companies holding these addresses are in constant flux.

In order to make this database useful to an application or Web site, we need to be able to make the request through some programming interface. Several existing packages assist in retrieving information from the NetGeo database. The PEAR system has a PHP package (see Resources), and a PERL module, CAIDA::NetGeo::Client, is available. However, it is a relatively straightforward task to make a request in whatever language you are using for your application or service. For example, a function in PHP for getting and parsing the NetGeo response looks like this:

--
1: function getLocationCaidaNetGeo($ip)
2: { 
3: $NetGeoURL = "http://netgeo.caida.org/perl/netgeo.cgi?target=".$ip; 
4:  
5: if($NetGeoFP = fopen($NetGeoURL,r))
6: { 
7:         ob_start();
8: 
9:         fpassthru($NetGeoFP);
10:         $NetGeoHTML = ob_get_contents();
11:         ob_end_clean();
12:
13: fclose($NetGeoFP);
14: }
15: preg_match ("/LAT:(.*)/i", $NetGeoHTML, $temp) or die("Could not find element LAT");
16: $location[0] = $temp[1];
17: preg_match ("/LONG:(.*)/i", $NetGeoHTML, $temp) or die("Could not find element LONG");
18: $location[1] = $temp[1];
19:
20: return $location;
21: }
--

Using DNS to Your Advantage

As previously mentioned, the NetGeo database slowly is becoming more inaccurate as IP address blocks change hands in company close-outs and absorptions. Several other tools are available for determining location, however. A description of the NetGeo infrastructure itself (see Resources) presents some of the methods it employed for mapping IP addresses and can be a source of guidance for future projects.

One of the most useful geolocation resources is DNS LOC information, but it is difficult to enforce across the Internet infrastructure. RFC 1876 is the standard that outlines „A Means for Expressing Location Information in the Domain Name System.“ Specifically, this is done by placing the location information of a server on the DNS registration page. Several popular servers have employed this standard but not enough to be directly useful as of yet.

To check the LOC DNS information of a server, you need to get the LOC type of the host:

--
$ host -t LOC yahoo.com
yahoo.com LOC 37 23 30.900 N 121 59 19.000 W 7.00m 100m 100m 2m
--

This parses out to 37 degrees 23′ 30.900“ North Latitude by 121 degrees 59′ 19.000“ West Longitude at 7 meters in altitude, with an approximate size of 100 meters at 100 meters horizontal precision and 2 meters vertical precision. There are several benefits to servers that offer their geographic location in this way. First, if you are connecting from a server that shows its DNS LOC information, determining your geolocation is simple, and applications may use this information without further work, although some verification may be useful. Second, if you are connecting on your second or third bounce through a server that has DNS LOC information, it may be possible to make an estimate of your location based on traffic and ping times. However, it should be obvious that these estimates greatly degrade accuracy.

It also is possible to put the DNS LOC information for your Web site in its registration (see Resources). If more servers come to use LOC information, geolocation accuracy will be much easier to attain.

Sidebar: host

host is a DNS lookup utility that allows users to find out various pieces of information about a host. The simplest use is doing hostname to IP address lookups and the reverse. The reverse, dotted-decimal IPv4 notation, is used for this, and the actual server that hosts the canonical name is returned. The type flag, -t, can be used to obtain specific information from the host record from the name server.

Where There’s a Name, There’s a Way

Many users hopping onto the Internet probably aren’t coming from a major server. In fact, most users don’t have a static IP address. Dial-up, cable modems and cell phone connections are assigned a dynamic IP address that may change multiple times in one day or not at all for several weeks. Therefore, it becomes difficult to tie these dynamic addresses to a single location.

To our rescue, these service providers typically provide an internal naming scheme for assigning IP addresses and associating names with these addresses. Typically, the canonical name of an IP address contains the country-code top-level domain (ccTLDs) in a suffix. CN is China, FR is France, RO is Romania and so on. Furthermore, the name even may contain the city or region in which the IP address is located. Often, however, this information is shortened to some name that requires a heuristic to determine. For example, in your service or application, a user may appear to be coming from d14-69-1-64.try.wideopenwest.com. A whois at this address reveals it is a WideOpenWest account from Michigan. Using some logic, it is possible to deduce that this user is connecting through a server located in Troy, MI, hence the .try. in the canonical name.

Some projects have been started to decipher these addresses (see Resources), and you also can get all of the country codes and associated cities and regions of a country from the IANA Root-Zone Whois Information or the US Geospatial Intelligence Agency, which hosts the GEOnet Names Server (GNS). The GNS has freely available data files on almost all world countries, regions, states and cities, including their sizes, geographic locations and abbreviations, as well as other information.

Information such as that presented on the GNS also can be used to provide users with utilities and services specific to their geographical locations. For example, it is possible to determine a user’s local currency, time zone and language. Time zone is especially useful for members of a community or chat group to determine when another friend may be available and on-line.

Where Are You Located?

Now that we’ve explained some of the techniques that can be used in geolocating Internet users by their IP addresses, we offer you a chance to try it out. Point your Web browser of choice here, and see how accurate or inaccurate the current results are. Please leave comments below about the accuracy of your results as well as any ideas you may have.

Comment viewing options

Flat list – collapsed
Flat list – expanded
Threaded list – collapsed
Threaded list – expanded
Date – newest first
Date – oldest first
10 comments per page
30 comments per page
50 comments per page
70 comments per page
90 comments per page

Select your preferred way to display the comments and click „Save settings“ to activate your changes.

Check out

Submitted by Anonymous (not verified) on Wed, 2005-10-26 15:28.

Check out this:
http://www.themidnightcoders.net/examples/messageserver/chat/mapchatajax.htm

The example does what the article is talking about.

Better URL for testing

Submitted by R. Scott Perry (not verified) on Wed, 2005-03-16 14:27.

The old URL to test geolocation no longer works. You may want to point people to http://www.DNSstuff.com/tools/city.ch instead.
-Scott

Geolocation URL restored

Submitted by Andy Turner (not verified) on Sat, 2005-04-30 09:53.

The link has been restored. It was accidentally moved during a site upgrade. My apologies.

Localisation and You (John Robinson at 1341 Crescent Dr….)

Submitted by Anonymous (not verified) on Tue, 2005-03-01 02:58.

Besides the worrying implications for privacy, I strongly believe on principle that you should not know my true IP nor be able to trace it to a specific geographical location. Geolocation by IP is a prime example of modern software trying so hard to be „smart“ that it ends up dumb. My browser (like almost all browsers) will explicitly identify the preferred language and region of my system based upon user-defined choices on the OS-level, and yet, sites like google.com will insist on trying to „guess“ my language/country based upon my IP, which is highly variable. Not that I entirely agree with browsers leaking that information in the first place, but it makes much more sense to base the rendering/forwarding of a webpage on OS-level user-defined choices than on a systems guesses based upon IP, especially for those with proxied systems. I do not just dislike modern localisation technologies, I oppose them unreservedly, along with all they represent.

Incorrect geolocation determination

Submitted by Pat Plaehn (not verified) on Wed, 2005-01-12 11:26.

The geolocation service you provided had me in Bordeaux, Gironde (department), aquitaine (region), France. I am in Dunstable, MA, USA.

Hello all! Does someone kn

Submitted by Anonymous (not verified) on Fri, 2004-11-26 14:15.

Hello all!

Does someone know a really free database with geolocations? I need something I can download and it should contain the Country and the City for a given IP.

Thanks!🙂

This IPs change too fast !

Submitted by Anonymous (not verified) on Wed, 2005-02-02 04:27.

Hi Folks.

This IP-Detection is a great idea. But it is NOT working 8-)))))

I tested different sources – most of them told me, that I was located in Australia 8-)))))) … well that is about 10.000 Kilometers from my real location.

To lockout people from a country – lets say Thailand – I use „whois -h whois.apnic.net“ and then parse the string I get back. Done in PHP this is much more easier (and quicker) than to rely on this databases.

… but – the Idea is good … just lacks some „central intelligence database“

Marco from: Shallaballa
Yes, it’s true – there are no more lovers left alive,
no one has survived… That’s why love has died. PSB

Block IP address country/region

Submitted by naveen (not verified) on Fri, 2005-09-09 07:34.

If you can help me tell how can we block IP region/country and state wise worlwide.
Using which language is more accurate and better.
It’s a really great idea-8-)))))
You guys are gr8
u can write me at denverus@lycos.com

Geolocation by IP address is misguided

Submitted by Vince Littler (not verified) on Mon, 2004-11-08 16:19.

IP [Internet Protocol] is about providing data transport services, not about providing client data such as geolocation.

I have no reference to hand on the different protocol levels, but I would refer to the OSI 7 layer model of datacommunications as an example.

Geolocation information belongs at a higher level than the IP level, where I do not know, but I tend to think it is a new service at an application level.

It is not for any server to look at the client and guess where it is, it is for the client to report where it thinks it is and it is for the client to engage services to discover where it is from some kind of local geolocation server. And only if the user so chooses.

For example, I might be in Gironde France now and know that I will be in Berlin tomorrow. If I plan to see a film in Berlin, location based services are only useful if I can say I am in Berlin, while I do my planning here in Gironde. I do not want to fight with a ‚helpful‘ service which pushes Gironde info at me when I really want Berlin info

Geolocation

Submitted by Jim (not verified) on Thu, 2004-11-25 07:14.

There are several good geolocation products in the market like below.

http://www.ip2location.com>

Also see

Submitted by Anonymous (not verified) on Sun, 2005-11-20 12:29.

geoip’s match

Submitted by Nicolas Bouliane (not verified) on Sun, 2004-11-07 16:11.

Hi people,

I’m proud to announce you that you can now
match by country with iptables,
e..g.:

iptables -A INPUT -m geoip –src-cc CA

more at: http://www.cookinglinux.org/geoip/
You can also read the offical netfilter’s thread:
https://lists.netfilter.org/pipermail/netfilter-devel/2004-November/017304.html

Thanks!
Nicolas Bouliane
cookinglinux TM

All private networks are in America

Submitted by Anonymous on Thu, 2004-10-28 01:00.

This is just stupid:

$ http://netgeo.caida.org/perl/netgeo.cgi?target=192.168.0.1
VERSION=1.0
TARGET: 192.168.0.1
NAME: IANA-CBLK1
NUMBER: 192.168.0.0 – 192.168.255.255
CITY: MARINA DEL REY
STATE: CALIFORNIA
COUNTRY: US
LAT: 33.98
LONG: -118.45
LAT_LONG_GRAN: City
LAST_UPDATED: 16-May-2001
NIC: ARIN
LOOKUP_TYPE: Block Allocation
RATING:
DOMAIN_GUESS: iana.org
STATUS: OK

CAIDA Example

Submitted by Andrew (not verified) on Tue, 2004-11-02 02:06.

This output was meant as an example of the CAIDA NetGeo output. I believe the actual reason for CAIDA pointing to Marina Del Rey was their default for unknown locations (and also how the site would appear internally to CAIDA).

For historical reasons

Submitted by El Buki (not verified) on Wed, 2005-01-05 23:26.

Unroutable ranges like 10.x.y.z are never re-registered, so where ARIN is concerned they still „belong“ to IANA, onetime co-ordinator of the entire IP address space. IANA was in Marina del Rey for easy access to UCLA (an original ARPAnet node dating to 1969).

Perl geolocation

Submitted by Anonymous on Thu, 2004-10-28 01:00.

CAIDA is old and inaccurate. If you’re using Perl you should be using IP::Country (free) or MaxMind (free-ish), both available from CPAN. If you’re using java or coldfusion, you should be using javainetlocator. I’ve written elsewhere about the accuracy of geolocation, and how city-level geolocation is inaccurate.

–Nigel Wetters Gourlay

p.s. SpamAssassin now uses IP::Country, which is flattering😉

Re: Geolocation by IP Address

Submitted by Anonymous on Wed, 2004-10-27 01:00.

I am in Pisa, Italy and your system placed me in Amsterdam, Netherlands.
The reason is simple: you queried arin.net but it is not the only Internet Registry. European ip addresses information is stored in ripe.net. You have to query the ripe database too.
I guess the same could apply to other Internet Registries like apnic.net for the Asia-Pacific region…

Anyway I like your approach. Good luck

Got mine bang on

Submitted by Anonymous on Wed, 2004-10-27 01:00.

right down to the correct town, good but also worrying…

Re: Geolocation by IP Address

Submitted by Anonymous on Tue, 2004-10-26 01:00.

Erm, Amsterdam/Netherlands is nowhere near Swindon/UK. You must be joking?

Re: Geolocation by IP Address

Submitted by Anonymous on Thu, 2004-10-28 01:00.

CAIDA is stupid and out of date. Your IP address is marked in the ARIN (US) database as assigned to RIPE (Europe). It doesn’t check where in Europe.

RIPE Network Coordination Centre (RIPE-NCC)
Singel 258
Amsterdam, NH 1016 AB
NL

Use an up-to-date database if you’re going to try this – IP::Country or JavaInetLocator. CAIDA was a proof of concept, but no one should be using it now.

Re: Geolocation by IP Address

Submitted by Anonymous on Wed, 2004-10-27 01:00.

Same for two different locations in Germany (one PPP pooled,
one static IP at a rackhoster).

They must assume that the whole of Europe is off for smoking
weed in Amsterdam😉

Re: Geolocation by IP Address

Submitted by Anonymous on Tue, 2004-10-26 01:00.

Maybe works well in the USA but not here.

The Internet just doesn’t work the same way here in the UK – most broadband connections are through British Telecom’s network, even if BT isn’t their ISP, or through a very small number of cable companies. Almost all dial-up users connect through the national BT phone network on ‚virtual‘, national numbers. The London INternet Exchange is the main peering point, so usually I expect to be placed in London.

The High Earth Orbit site placed me in Amsterdam (that’s in the Netherlands by the way).

Re: Geolocation by IP Address

Submitted by Anonymous on Tue, 2004-10-26 01:00.

I’m in Venezuela and the reported IP address is in Uruguay!

Re: Geolocation by IP Address (inaccurate results)

Submitted by Anonymous on Tue, 2004-10-26 01:00.

Depending on the intended use, this system will be useful/not useful. In my case (and likely everyone else’s) it reports the location of my ISP’s point of presence, not the actual location of where the IP is routed. In my case, it’s about 25-30 miles off target. Now, granted, it knows the state, and pretty close the locality, so for something keying off of state/general city area, it might be useful. But if you want GPS level accuracy, this simply isn’t going to give it to you.

Re: Geolocation by IP Address

Submitted by Anonymous on Tue, 2004-10-26 01:00.

My real location in the great state of Tennessee shows up as in the heart of Australia

Re: Geolocation by IP Address

Submitted by Anonymous on Tue, 2004-10-26 01:00.

Well my supposed location was at least still in Europe, 1150 kms due north of the real location. But according to the map on the site it put me on the Greenwich meridan and the equator.

Re: Geolocation by IP Address

Submitted by nilspace (not verified) on Tue, 2004-10-26 01:00.

As discussed in the article, the current utilities will sometimes produce erroneous results. Australia is the ‚default‘ unknown response.

I have put a section below the map on the webpage for you to input your actual location. It is then possible to apply new heuristics for determining location when it is unknown (or incorrect).

Andrew

Re: Geolocation by IP Address

Submitted by Anonymous on Thu, 2004-10-28 01:00.

Manually adding IP addresses to a database will lead to great suffering. How will you ensure that the changes made are accurate in six months‘ time?

–Nigel Wetters Gourlay

Re: Geolocation by IP Address (doing it in Java)

Submitted by Anonymous on Tue, 2004-10-26 01:00.

Hi,

About a month ago, I wrote a small Java library that uses different Geo Internet services to provide you with location information. It’s really basic, but it works for me.

See http://www.coffeebreaks.org/oss/projects/geolocator/

Any comments, patches appreciated.

Jerome

Re: Geolocation by IP Address (doing it in Java)

Submitted by Anonymous on Thu, 2004-10-28 01:00.

You assume that by combining different Geo Internet services you will improve accuracy, which isn’t the case. You’d be spending your time in a better way by measuring the accuracy of the various services and using just the most accurate. I’m sure that you’ll find this one to be the best.

–nwetters

Geolocation by IP Address sucks

Submitted by Anonymous on Mon, 2004-10-25 01:00.

I’m somewhere … and google tries to make me happy with a language I don’t understand (great!)
I’m trying to get an online quote, and the server tells me „this service is only available for our US customers“ … great ! (cyclades; fortunately I’ve got a proxy somewhere else😉
I never liked when computers are trying to predict what I want (i.e. getting too smart, ‚cause in 90%, they are plainly wrong)

again

Submitted by Anonymous on Mon, 2004-10-25 01:00.

yep, I know I shouldn’t follow-up my own article … but so-what …
perhaps some people would prefere postings/comment like:
Anonymous@[Lat: 49.5817?, Lon: 6.1159?, Alt: 369m] ?
(you may send snail-mail flames to this position (it’s authentic))

-frank

Hostip.info

Submitted by Anonymous on Mon, 2004-10-25 01:00.

Sob. I’m rather disappointed that my site http://hostip.info didn’t make it into the ‚Resources‘ section at least … especially considering it is free, the DB is open and available, and there’s an API if you don’t want to do the whole DB thing. You can even embed the zoom-in applet in your own page if you want…

Simon

Re: Geolocation by IP Address

Submitted by Anonymous on Mon, 2004-10-25 01:00.

And this is all still available after everyone freaked out about Sean Gorman? Talk about shooting-the-messenger-based information technology security solutions for the Enterprise.

(Enterprise? is a registered trademark of Paramount Pictures Corporation)

Recommending counter, Ip address detector ..

Submitted by Anonymous (not verified) on Sat, 2005-02-12 07:33.

Recomending 1
http://www.showmyip.com/es/

Recomending 2

http://cqcounter.com/?sts,l20ip,,,,daniel12

DANIEL 12= BOOK OF DANIEL CHAPTER TWELVE (BIBLE END TIMES)

Recomending 3

http://geocities.com/balconcillofc/nolonghair.html (JESUS DID NOT USE LONG HAIR)

Recommending counter, Ip address detector ..

Submitted by Anonymous (not verified) on Sat, 2005-02-12 07:25.

http://interactive.linuxjournal.com/article/7856

Schreibe einen Kommentar

Bitte logge dich mit einer dieser Methoden ein, um deinen Kommentar zu veröffentlichen:

WordPress.com-Logo

Du kommentierst mit Deinem WordPress.com-Konto. Abmelden / Ändern )

Twitter-Bild

Du kommentierst mit Deinem Twitter-Konto. Abmelden / Ändern )

Facebook-Foto

Du kommentierst mit Deinem Facebook-Konto. Abmelden / Ändern )

Google+ Foto

Du kommentierst mit Deinem Google+-Konto. Abmelden / Ändern )

Verbinde mit %s