views:

220

answers:

4

Looking to implement better geo-location with Python.

Thanks.

+4  A: 

It is not a Python lib. But http://ipinfodb.com/ provides a webservice that can be easily wrapped by Python code

luc
+3  A: 

Hostip.info is a community-based project that maintains a database mapping IP addresses to cities. The also have a very easy-to-use API. (Just pass in your ip address after the 'ip=' in the GET request string):

import urllib
urllib.urlopen('http://api.hostip.info/get_html.php?ip=12.215.42.19&position=true').read()
print(response)
doug
+1  A: 

You may find these modules useful: MaxMind's GeoIP and its pure version, as well pytz.

ony
+1  A: 

I have found that IP2Location.com has Python library, will it be useful for the answering the question?

Below is sample codes from the Website, but you can download and see the library with sample database:

import IP2Location;

IP2LocObj = IP2Location.IP2Location();
IP2LocObj.open("data/IP-COUNTRY-SAMPLE.BIN");
rec = IP2LocObj.get_all("19.5.10.1");

print rec.country_short
print rec.country_long
print rec.region
print rec.city
print rec.isp
print rec.latitude
print rec.longitude
print rec.domain
print rec.zipcode
print rec.timezone
print rec.netspeed
print rec.idd_code
print rec.area_code
print rec.weather_code
print rec.weather_name
hexahow