April 14th, 2005


I'm processing some log data coming in from around the world, so I thought it would be nice to be able to look up IP addresses by country. Although more specific geographic data on IP numbers seems to be available only for a price, the country mapping is available for free in the Perl module Geo::IPfree.

I've turned this into a Python module, ipfree.py. Unlike the Perl package, which stores the database in an auxiliary file, this Python module is just a single file containing the entire database and a simple lookup function. It's a bit big (nearly a megabyte), but it's easy to use and it works.
>>> import ipfree
>>> ipfree.lookup('')
('CA', 'Canada')
>>> ipfree.lookup('')
('NL', 'Netherlands')
Hope someone out there has a use for it.