Free IP Locator API - Convert IP Addresses to Zip Codes with PHP

If you just want a free site to use:
IP Address Locator with Map


If you want a quick PHP solution, try this:

$ip = 'xxx.xxx.xxx.xxx';
var_dump(json_decode(file_get_contents("https://freegeoip.net/json/$ip"),true));



If you want quick responses, you can install the freegeoip server on ubuntu. This will give you your own personal IP locator service to use privately (or publicly if you are a nice guy):

Install golang 1.1.1
--------------------

sudo apt-get install python-software-properties
sudo add-apt-repository ppa:duh/golang
sudo apt-get update
sudo apt-get install golang
go version

Set your go environment variables
---------------------------------

export GOROOT=/usr/lib/go

Install freegeoip
-----------------

git clone https://github.com/fiorix/freegeoip.git
cd freegeoip
go build

Download the database
---------------------

cd db
./updatedb
file ipdb.sqlite

Run it
------

cd ..
./freegeoip

cron script to keep the server running (replace $FREEGEOIP_PATH)
----------------------------------------------------------------

#!/bin/bash
ps cax | grep -v grep | grep freegeoip > /dev/null
result=$?
echo "${result}"
if [ "${result}" -eq "0" ] ; then
        echo "freegeoip is already running" #>>/home/work/cgcron
else
        cd $FREEGEOIP_PATH
        ./freegeoip &
fi

cron script to update the database regularly (replace $FREEGEOIP_PATH)
----------------------------------------------------------------------

#!/bin/bash
cd $FREEGEOIP_PATH/db
./updatedb &