How can I geolocate a bunch of IP addresses with Python?

data-visualization, geolocation, python, visualization

Solution

You can use the hostip.info API. For example:

http://api.hostip.info/get_html.php?ip=64.233.160.0

So your Python code using `urllib2` would be:

import urllib2
f = urllib2.urlopen("http://api.hostip.info/get_html.php?ip=64.233.160.0")
data = f.read()
f.close()

Then retrieve the data from that returned result.

If you require longitude and latitude, use the `position=true` flag:

http://api.hostip.info/get_html.php?ip=64.233.160.0&position=true

Problem

I have a list of ~300 IP addresses that I would like to plot on a map of the world. Can you explain roughly how I could do that with Python? EDIT: I'm also interested in the visualization part of the question

Original source