Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is there a console command that takes an IP address as an input and shows its geographical information like city, country, ISP, etc.?

share|improve this question
up vote 15 down vote accepted

The command is the easy part, the difficult part is having access to a database.

For example, Ubuntu has a free database with a command line query tool (geoiplookup) in the geoip-bin Install geoip-bin package. But it only shows country information, and uses a static (hence out-of-date) database. This tool can also query the MaxMind GeoIP database, if you have a subscription there.

There are various GeoIP databases that you can look up. They're generally meant to be viewed through a web browser, but you can look for a scraping script. For example, here's a ruby script to retrieve data from the MaxMind database. Note that scraping may be against the database's terms of service.

share|improve this answer
    
just used the ubuntu geoiplookup and it is good enough. – BuZain Feb 15 '11 at 17:57
    
CentOS# yum install GeoIP – zmonteca Jul 1 '14 at 22:50

This trick is even nicer and doesn't require any external packages:

curl ipinfo.io/23.66.166.151
share|improve this answer
2  
In case ipinfo.io gets offline someday, ifconfig.me provides a similar service (plus a REST-like API). But ifonfo.io seems much faster. – cedbeu Mar 5 '15 at 15:48
    
Meh, doesn't allow hostnames... – erm3nda Mar 11 at 4:47
1  
$ host yourdomain.com | cut -d ' ' -f 4 | curl ipinfo.io/$1 – zmonteca Mar 22 at 15:57

Here's another great option. Instructions here: http://kbeezie.com/geoiplookup-command-line/

For example, on Centos:

$ sudo yum install GeoIP GeoIP-data
$ geoiplookup 8.8.4.4

Works perfectly.

And of course, you can always set this up as a cron:

$ /usr/bin/geoipupdate
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.