logo RSSTwitter

Free IP address geolocation tools
IP Address Location Command Line Tool
Bash script for command line IP geolocation that can be use on any linux distribution.

#!/bin/sh
#
###
### For assistance, please visit forum.ipinfodb.com
# 
# Created by Eric Gamache on 2009-05-26
# Version 1.0 by Eric Gamache -- 2009-06-04
# Version 1.1 updated by Marc-Andre Caron -- 2009-06-08 .. Added timezone
# Version 1.2 updated by Eric Gamache -- 2009-06-08 .. fix minors bugs.
# Version 1.3 updated by Marc-Andre Caron -- 2010-02-11 .. new timezone support, reduced complexity of the script.
# 
# This script is provided "as is", with absolutely no warranty expressed or 
# implied. Any use is at your own risk. Permission to use or copy this 
# script for any purpose is hereby granted without fee. Permission to 
# modify the code and to distribute modified code is granted, provided 
# the above notices are retained, and a notice that the code was modified 
# is included with the above copyright notice. 
#
###############################################
####
####
####
URL="http://ipinfodb.com/ip_query.php?ip="
#
WGET_OPTION="=-b -q --wait=3 --waitretry=2 --random-wait --limit-rate=9578 "
WGET_AGENT="Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)" 
#
ERROR=0
#
###############################################
if [ "$1" = "" ]; then
  ERROR=1
else
  IP=$1
  HTTP_LINK_XML="$URL""$IP""&output=xml&timezone="
  HTTP_LINK_JSON="$URL""$IP""&output=json&timezone="
fi
##############
if [ "$2" != "" ]; then
  if [ "$2" != "json" ] && [ "$2" != "xml" ] ; then
    ERROR=1
  fi
  TYPE="$2"
else
  ERROR=1
fi
##############
if [ "$3" != "" ]; then
  if [ "$3" != "true" ] && [ "$3" != "false" ] ; then
    ERROR=1
  fi
  TIMEZONE="$3"
else
  ERROR=1
fi
###############################################
 
###############################################
if [ "$ERROR" != "0" ]; then
  echo " "
  echo " usage : $0 IP TYPE TIMEZONE"
  echo " Where IP is the IP to check"
  echo " TYPE is the output type (xml|json)"
  echo " TIMEZONE is to show timezone data or not (false|true)"
  echo " Big thanks to the team of IPInfoDB (http://ipinfodb.com)"
  exit
fi
###############################################
#
TST_wget=`wget > /dev/null 2>&1`
#
ErrorLevel=$?
#
if [ "$ErrorLevel" != 1 ] ; then
  echo " ----" 
  echo " wget not found; please install it for proper operation."
  echo " ----" 
  exit
fi
###############################################
###############################################
#######
#######
if [ "$TYPE" = "json" ]; then
  JSON_Info=`wget -qO- --user-agent="$WGET_AGENT" $HTTP_LINK_JSON"$TIMEZONE" 2>&1`
  echo "$JSON_Info"
else
  XML_Info=`wget -qO- --user-agent="$WGET_AGENT" $HTTP_LINK_XML"$TIMEZONE" 2>&1`
  echo "$XML_Info"
fi

Servers location and uptime

We have 3 servers. Two are are load balanced & highly available (ldirectord + heartbeat setup). They are located in Montreal, Canada and used for the primary domain (ipinfodb.com). We also have a third server located in Los Angeles, US (backup.ipinfodb.com or us.ipinfodb.com). It can be used as the first server you query but keep in mind that it's not redundant as our main server in case of hardware failure. Our goal is to have over 99.99% uptime on the main server. 100% uptime can be reached by adding a failover server (eg backup.ipinfodb.com) in your code.

Query limit

We do not have a specific daily limit but queries that are at a rate faster than 2 per second will be put in "queue". If you stay below 2 queries/second everything will be normal. If you go over the limit, you will still get an answer for all queries but they will be slowed down to about 1 per second. This should not affect most users but for high volume websites, you can either use our IP database on your server or we can whitelist your IP for 5$/month (simply use the donate form and leave a comment with your server IP). Good programming practices such as not querying our API for all page views (you can store the data in a cookie or a database) will also help not reaching the limit.

Keeping in touch for updates

The best way to get updates and news is with our RSS feed or on Twitter

Support

For all non googable questions, visit the forum. We also offer custom integration.