Free geo ip is a free web service that will provide you with all the information you need.
http://freegeoip.net/static/index.html
You call the service
http://freegeoip.net/{format}/{ip_or_hostname}
And the service returns in JSON format:
show({"city": "Mountain View", "region_code": "CA", "region_name": "California", "metrocode": "807", "zipcode": "94043", "longitude": "-122.057", "country_name": "United States", "country_code": "US", "ip": "209.85.145.147", "latitude": "37.4192"});
Since it is free, you can only process 1000 requests per hour.
source share