views:

355

answers:

3

Is it possible to find the zip code based on a users IP address using python / django (not geodjango)? I assume I would have to use a web service, but I would really like to just be able to query a database if possible.

I am using geopy right now, so it would be cool if I could integrate that somehow.

A: 

You can't collect a real zip code from an IP address as these are assigned by ISP's when you route threw their connection.

Taos
Of course you cant collect the real address of the user, but there are many services which help you approximate a user's address via their request IP address.
mitchf
+1  A: 

http://www.ip2location.com/python.aspx

import IP2Location;

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

print rec.zipcode

I don't have any experience with this package but it looks like it will do what you want.

EDIT: Actually it looks like this is just searching through a data file that they sell -- so probably not that useful if you are looking for something free.

swanson