Using DNS to determine location of connection to redirect user?

michaelsanford

Translator, Web Developer
I'm curious how I can implement (presumably via DNS resolution) a way to determine a user's general location/country of connection's origin.

For a good example visit www.google.com (or if you're in the US www.google.ca)

I'm in Canada, and I always get redirected to google.ca, I seem to remember reading somewhere (I think an error message...) that this is done by a DNS lookup of my IP address to determine my ISP.
 
I tried google.ca and it stayed put on Google Canada - no redirect at all. My ISP is in Minneapolis, MN (close to Canada, but still...)

Maybe my ISP disallows IP address detection or something.
 
Mike, it could be that way back when you first went to Google that you selected Canada as your location and it is now storing a cookie to that effect? Could also be that since Google.com is the primary site, that only it supports redirection, they probably assume that anyone going explicitly to google.ca is there because they want to be there.

Keep in mind that even doing the dns lookup, that does not guarantee any geographic region. What if someone comes in on IBM.com?

This caveat is especially true if you're thinking of doing anything involving language (i.e. switching to Spanish if their domain resolves to .es). You'll notice that many websites don't even bother to do that type of determination. At least partially because doing that reverse lookup would be somewhat expensive for heavily travelled sites, but primarily because it's not worth the confusion to the user. Better to have them explicitly state what content their interested in (imagine the poor Canadian user who really wants to go to google.com and they keep typing it in because they keep getting redirected to google.ca and they don't notice the little link at the bottom. That and your redirection logic has to be smart enough to figure out that they just came from google.ca and not redirect them right back again :)
 
The complicated nature of what you describe is precisely why I was curious of how it was done :)

I am no 100% sure that (for example google) uses reverse DNS, but I am certain that I never selected google.ca it did that for me, and continues to in fact. I only guessed it was reverse DNS because I (vaguely) remember at some point that I got an error message displayed on the page (perhaps not google though) that my location could not be determined by a DNS lookup. I might have been daydreaming though hehe :p

Thanks for the reply!
 
Google will recognize a Finnish IP and send you to google.fi when you try google.com but there is also a little link to get to the real google if you want. In the US I can go to google.fi and it will not send me back to google.com so you are not crazy up there in the Great White North, eh.

Any way what I think they are doing is looking at your IP address itself. IP addresses are allocated in blocks to different authorities that then distribute them out to us plebes. The powers that be are divided up along political boundaries for the most part so it is easy to say that "this is a Canadian IP address" because it came from block 123.45.*.* which is administered by the Royal Mounted Network Guys.

Now this is not 100% reliable since you could use a proxy in Fiji and then they would not send you to google.ca but to google.fj (is it fj? well if not lets pretend) because they would see the Fijian IP address of the proxy.

Now where this is really important for google is not so much in the fact that they can better guess the language you want everything in but rather so that can filter the results they give you by country. For instance I just typed Nazi into froogle.com and got 65K matches all of which they legally cannot show to someone in France or Germany.

-Eric
 
Back
Top