Ping ([info]zestyping) wrote,
@ 2005-04-14 17:10:00
Previous Entry  Add to memories!  Tell a Friend!  Next Entry
ipfree.py
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('129.97.128.15')
('CA', 'Canada')
>>> ipfree.lookup('194.109.137.226')
('NL', 'Netherlands')
>>>
Hope someone out there has a use for it.


(Post a new comment)


[info]nibot
2005-04-15 12:28 am UTC (link)
nice.

(Reply to this)


[info]chimerically
2005-04-15 12:42 am UTC (link)
Very cool!

(Reply to this)


[info]nanomonkey
2005-04-15 04:41 am UTC (link)
cool...now I can say "ipfreely"

(Reply to this)

Cool!
(Anonymous)
2005-04-19 02:28 am UTC (link)
Thanks for doing this. I've been looking for something like this. I added the usual


'if __name__ == '__main__':'

to make it a command-line utility. Rune.

(Reply to this)

Have you looked at ip2cc?
(Anonymous)
2005-04-19 03:02 pm UTC (link)
It includes script to gather data and create database:
http://sourceforge.net/project/showfiles.php?group_id=47230&package_id=56471&release_id=314998

(Reply to this) (Thread)

Re: Have you looked at ip2cc?
[info]zestyping
2005-04-20 04:24 am UTC (link)
Oh, i missed that. Thank you. I thought someone must have done something like this.

I guess this is why we should all be using PyPI.

(Reply to this) (Parent)(Thread)

Re: Have you looked at ip2cc?
(Anonymous)
2005-04-20 07:00 am UTC (link)
Sure: http://python.org/pypi?%3Aaction=search&name=ip2cc

(Reply to this) (Parent)(Thread)

Re: Have you looked at ip2cc?
[info]zestyping
2005-04-20 07:07 am UTC (link)
Thanks.

Sigh. PyPI's search interface needs work.

(Reply to this) (Parent)(Thread)

Re: Have you looked at ip2cc?
(Anonymous)
2005-04-20 07:53 am UTC (link)
What do you mean? Search works fine for me:
http://python.org/pypi?%3Aaction=search&summary=country+by+IP

As well as google can be used for this task
http://www.google.com/search?q=country+IP+site:python.org+inurl:pypi

(Reply to this) (Parent)(Thread)

Re: Have you looked at ip2cc?
[info]zestyping
2005-04-20 08:32 am UTC (link)
1. No search box on the first page of PyPI. (Even better would be a search page on the front page of python.org.) From the Python home page, a visitor has to click on PyPI, then click on Search to get to a separate search page.

2. Six different search fields with no explanation. How is the user supposed to know which box to use? What does "hidden" mean? (I tried "keywords" and typed in "country", which failed. Then i tried "country" for the description, and that failed too.)

3. Mislabelled result fields. When you do get to ip2cc, it shows "Lookup country by IP address" in the Description column. But searching for "country" in the description doesn't work. I assume the Description column is really the Summary column?

Ugh. There should be no search page. There should be a single text field (appearing on both the PyPI page and the Python front page) where you enter some words, and immediately get a list of packages that have those words anywhere in their documentation or module docstrings. Type in your search words, hit Enter, click once, and you've downloaded the package.

(Reply to this) (Parent)

(Reply from suspended user)

(Reply from suspended user)

Create an Account
Forgot your login or password?
Login w/ OpenID
English • Español • Deutsch • Русский…