[Subject Prev][Subject Next][Thread Prev][Thread Next][Subject Index][Thread Index]

Re: Mapping IP address to country

Binand Raj S. wrote (binand@xxxxxxxxxxxxxxxxxxxxx):

> > The IP address is got using $REMOTE_ADDR in PHP.
> > Now how do I map this to the country of origin.

> You could do a whois lookup and try to parse the o/p of all the whois
> servers out there, but I would recommend against it. The tremendous
> additional traffic that this would generate would probably affect the
> performance of your server. Apache also has an option that enables reverse
> DNS lookups on client IP addresses, but is turned off by default because
> of performance reasons.

If you do it offline, reverse DNS can be a practical way of doing the trick.
Log the IPs to a file, periodically extract all unique IPs from the file and
do your reverse DNS lookups. Hopefully, you will be generating fewer queries.

This is already implemented in apache, look for `logresolve' in your apache
distro. See http://httpd.apache.org/docs/programs/logresolve.html

Since IPs do not always map to the same names (dynamic IP, dynamic DNS, etc),
the DNS method can sometimes fail.

> But please remember that you are invading the privacy of the surfer.

I second this, the "correct" (read ethical/polite) way of doing this is to
~request~ this information instead.

- Raja