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


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][5] 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.

  • 1
    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
  • @StephenRauch Thanks but please use the official replacement for the broken bit.ly link: hostmar.co/software-small – Gilles 'SO- stop being evil' Apr 3 '17 at 0:23
  • 1
    @StephenRauch The apt link only works with a browser plug-in that's part of the default Ubuntu installation but rarely installed otherwise. – Gilles 'SO- stop being evil' Apr 3 '17 at 0:29
  • These are in Homebrew for Mac as well: geoipupdate; geoiplookup ... – Pysis Nov 25 '18 at 17:06

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

curl ipinfo.io/
  • 3
    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
  • 1
    $ host yourdomain.com | cut -d ' ' -f 4 | curl ipinfo.io/$1 – zmonteca Mar 22 '16 at 15:57
  • 3
    ipinfo.io is free for 1000 requests/day (see their pricing documentation). – Matthieu Nov 14 '16 at 15:03
  • 5
    Another alternative: curl ipinfo.io/$(dig +short yourdomain.com) – John Red Dec 7 '16 at 17:00
  • 3
    If someone ever hits the ceiling on the ipinfo.io API (lucky you?), there is also freegeoip.net which has a mind-blowing 15,000 requests per hour limit. (Which under the hood seems to be running the geoiplookup from the other answers) – samthecodingman Mar 9 '17 at 13:52

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

For example, on Centos:

$ sudo yum install GeoIP GeoIP-data
$ geoiplookup

Works perfectly.

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

$ /usr/bin/geoipupdate
  • geoipupdate is a MaxMind tool, you need a subscription and the licence key on /etc/GeoIP.conf. I couldn't use the free alternative (Received an unexpected HTTP status code of 401). – Pablo A Mar 9 '18 at 22:47

Or use whois

$ whois |grep country -i -m 1 |cut -d ':' -f 2 |xargs US

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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