best way to use an IP address to find what state....

For all coding issues - MODers and programmers, HTML and more.

Moderators: Jeff250, fliptw

Post Reply
User avatar
Isaac
DBB Artist
DBB Artist
Posts: 7737
Joined: Mon Aug 01, 2005 8:47 am
Location: 🍕

best way to use an IP address to find what state....

Post by Isaac »

...someone's in.

Using python cgi on my server, I can log a user's the IP address when they come to my site, along with most other activity. So I would like my new comment box to take this info and post what State or province the comment came from, next to the name of the person and time stamp.

I wondering if there's a common application on the server I can use, rather than have python use a different website. I think cpanel does this to some degree, so I think my CGI app could do this too.
❉⊱•═•⊰❉⊱•═•⊰❉⊱•═•⊰❉❉⊱•═•⊰❉⊱•═•⊰❉⊱•═•⊰❉❉⊱•═•⊰❉⊱•═•⊰❉⊱•═•⊰❉
-⎽__⎽-⎻⎺⎺⎻-⎽__⎽--⎻⎺⎺⎻-★ ·:*¨༺꧁༺ :E ༻꧂༻¨*:·.★-⎽__⎽-⎻⎺⎺⎻-⎽__⎽--⎻⎺⎺⎻-
❉⊱•═•⊰❉⊱•═•⊰❉⊱•═•⊰❉❉⊱•═•⊰❉⊱•═•⊰❉⊱•═•⊰❉❉⊱•═•⊰❉⊱•═•⊰❉⊱•═•⊰❉
User avatar
Jeff250
DBB Master
DBB Master
Posts: 6536
Joined: Sun Sep 05, 1999 2:01 am
Location: ❄️❄️❄️

Re: best way to use an IP address to find what state....

Post by Jeff250 »

There are tables for IP address -> country lookups (e.g. D2x XL comes with one as a *.csv file). I've never seen them for IP address -> state/province, but maybe they exist. They'd probably be more temperamental though. Are you expecting all of your visitors to even be from the U.S. or Canada?

This is probably a bad idea though in general due to proxies. All AOL traffic used to be (and perhaps still is) proxied through Virginia. Someone might be using Tor, which means they might show as a different state (or country) every time they post. Maybe you should just let users optionally say where they are from? They might not even like being forcibly identified by state.
User avatar
Isaac
DBB Artist
DBB Artist
Posts: 7737
Joined: Mon Aug 01, 2005 8:47 am
Location: 🍕

Re: best way to use an IP address to find what state....

Post by Isaac »

Yeah. I guess it's not worth the effort. But maybe a section that lets users opt into stating what place they're from would be fine.

Thanks.
❉⊱•═•⊰❉⊱•═•⊰❉⊱•═•⊰❉❉⊱•═•⊰❉⊱•═•⊰❉⊱•═•⊰❉❉⊱•═•⊰❉⊱•═•⊰❉⊱•═•⊰❉
-⎽__⎽-⎻⎺⎺⎻-⎽__⎽--⎻⎺⎺⎻-★ ·:*¨༺꧁༺ :E ༻꧂༻¨*:·.★-⎽__⎽-⎻⎺⎺⎻-⎽__⎽--⎻⎺⎺⎻-
❉⊱•═•⊰❉⊱•═•⊰❉⊱•═•⊰❉❉⊱•═•⊰❉⊱•═•⊰❉⊱•═•⊰❉❉⊱•═•⊰❉⊱•═•⊰❉⊱•═•⊰❉
User avatar
Isaac
DBB Artist
DBB Artist
Posts: 7737
Joined: Mon Aug 01, 2005 8:47 am
Location: 🍕

Re: best way to use an IP address to find what state....

Post by Isaac »

Putting this here in case I forget...

http://ipinfodb.com/ip_location_api.php
❉⊱•═•⊰❉⊱•═•⊰❉⊱•═•⊰❉❉⊱•═•⊰❉⊱•═•⊰❉⊱•═•⊰❉❉⊱•═•⊰❉⊱•═•⊰❉⊱•═•⊰❉
-⎽__⎽-⎻⎺⎺⎻-⎽__⎽--⎻⎺⎺⎻-★ ·:*¨༺꧁༺ :E ༻꧂༻¨*:·.★-⎽__⎽-⎻⎺⎺⎻-⎽__⎽--⎻⎺⎺⎻-
❉⊱•═•⊰❉⊱•═•⊰❉⊱•═•⊰❉❉⊱•═•⊰❉⊱•═•⊰❉⊱•═•⊰❉❉⊱•═•⊰❉⊱•═•⊰❉⊱•═•⊰❉
R e v
DBB Admiral
DBB Admiral
Posts: 1121
Joined: Wed Mar 24, 1999 3:01 am

Re: best way to use an IP address to find what state....

Post by R e v »

http://www.maxmind.com/app/geolitecity

Free monthly city-level data set.
Post Reply