mdog has asked for the wisdom of the Perl Monks concerning the following question:

Brethern --

Does anyone know a good, free source (perl module, web page, program) that when you give it an IP, it will spit back city, state, country, etc?

I am processing my webserver logs and want to find out where people are coming from.

I used to make connections to: http://www.networldmap.com/TryIt.htm but they kill connections after 8 times (not that I blame them) and it worked great.

I understand that NetGeo is no longer updated and is therefore no longer reliable.

Hoping other people have ideas...

Thanks,
mdog

Replies are listed 'Best First'.
•Re: IP to Location Source?
by merlyn (Sage) on Oct 02, 2003 at 18:50 UTC
    Does anyone know a good, free source (perl module, web page, program) that when you give it an IP, it will spit back city, state, country, etc?
    That's impossible to do with any certainty. It's about as reliable as the "referer" header. {grin}

    -- Randal L. Schwartz, Perl hacker
    Be sure to read my standard disclaimer if this is a reply.

Re: IP to Location Source?
by hardburn (Abbot) on Oct 02, 2003 at 18:54 UTC

    There hasn't been a reliable way to do this since people started using a lot of dynamically-assigned IPs, NAT, and proxies. Dija know that all international traffic coming out of Canada is on one of three IP addresses? If this was back 7-10 years ago, we might be able to get somewhere with this, but not now. Probably never will until IPv6 gains a significant foothold--perhaps not even then.

    ----
    I wanted to explore how Perl's closures can be manipulated, and ended up creating an object system by accident.
    -- Schemer

    Note: All code is untested, unless otherwise stated

Re: IP to Location Source?
by NetWallah (Canon) on Oct 02, 2003 at 19:04 UTC
    City/state would probably be meaningless - many ISPs and companies use the same address range for several physical locations, and most companies use NAT addresses.

    The IP::Country module can help get the Country info, which should be somewhat meaningful.

Re: IP to Location Source?
by simonm (Vicar) on Oct 02, 2003 at 19:42 UTC
    Sorry, not that I know of. You can typically resolve the IP address block to a country or region (see IP::Country), and you can try using "whois" to get the address of the ISP or company, but those addresses are coarse-grained and unreliable.

    There are several commercial services around (cf. Quova, Geobytes), which rely on a human staffers and lengthy analysis to build up more specific mappings between address and location.

Re: IP to Location Source?
by revdiablo (Prior) on Oct 02, 2003 at 22:44 UTC

    The other monks have answered your question rather well, it seems, but I thought perhaps I might have a suggestion that could be of use as well. Maybe you could simply ask your users where they're from? This kind of thing would be trivial to implement, and would probably come across far less "sneaky" than inferring from logs. And if you make it optional, I think people would be more likely to simply put nothing instead of filling it with a false value. Also, once you have people actively announcing where they're from, you could correlate this information with their IP address in the future. :)

    HTH