What python libraries can tell me approximate location and time zone given an IP address? What python libraries can tell me approximate location and time zone given an IP address? python python

What python libraries can tell me approximate location and time zone given an IP address?


Hostip.info is an open-source project with the goal to build/maintain a database mapping IP addresses to cities. Their about page explains the data sources relied on to populate this database.

Using HostIP, there are two ways to get location data from an IP address:

They also have a well-designed and easy-to-use RESTFUL API: just pass in your ip address after the i***p=*** in the GET request string):

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

Second, the Project Website also makes its complete database available for download.


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

http://api.ipinfodb.com/v3/ip-city/?key=<your_api_key>&ip=74.125.45.100http://api.ipinfodb.com/v3/ip-country/?key=<your_api_key>&ip=74.125.45.100

You need to request a free API key. See the API doc for details.


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