Forum Moderators: open

Message Too Old, No Replies

Detect IP address "country code" and redirect script?

         

thaiguy

12:13 am on Jan 26, 2004 (gmt 0)

10+ Year Member



Hello. I've found some Javascripts for detecting a person's *entire* IP address and then redirecting/blocking etc., but I'm wondering if there are any scripts that can determine the country location only and act on that? I'd assumed the prefix of any IP address was the "country code", like a telephone number, but can't find any lists anywhere on the net.

For example, let's say IP addresses for Thailand always and only start with 202. and 203. I want to have a Javascript that says "Scan for IP address, if it begins with 202. or 203. redirect here, otherwise redirect there". But like I said before, I can't find any lists of which prefixes match which countries, so maybe my understanding of IP addresses is wrong.

If IP addresses are dynamically created and random, the only other choice I'd have is detecting the default language of the browser and then redirecting. The downside of this approach is people OUTSIDE Thailand would also be redirected, and those within Thailand with their default language other than Thai would NOT get redirected. I'd prefer to have the first option, detecting IP address and redirecting based on country location only. It's more reliable.

Could anyone advise, please?

BlobFisk

1:25 pm on Jan 26, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



This is something that you'd need to do at the server side rather than client side.

There is no direct relationship between IP addresses and location that can be got from looking at the IP number - you need to do a lookup to determine this.

There are companies out there that specialise in this sort of service.

HTH

Zaphod Beeblebrox

1:39 pm on Jan 26, 2004 (gmt 0)

10+ Year Member



Here's a free one: http://ip-to-country.directi.com/forum/6

[edited by: engine at 8:25 pm (utc) on Feb. 21, 2004]
[edit reason] de-linked [/edit]

jasshep

6:52 pm on Jan 26, 2004 (gmt 0)

10+ Year Member



Hi
I just tried
http://ip-to-country.directi.com/forum/6
I use AOL from the UK but they indicated my IP was from the United States. It would appear they are not foolprood.

[edited by: engine at 8:26 pm (utc) on Feb. 21, 2004]
[edit reason] de-linked [/edit]

thaiguy

5:44 am on Jan 27, 2004 (gmt 0)

10+ Year Member



Thank you to everyone. I'll try the free service, and also might use "detect language and redirect" method I mentioned as well.

Zaphod Beeblebrox

1:14 pm on Jan 27, 2004 (gmt 0)

10+ Year Member



It would appear they are not foolprood.

Correct. They base it on which IP ranges are given to which host. AOL is an american company.

jasshep

12:19 am on Jan 30, 2004 (gmt 0)

10+ Year Member




BBC Worldwide Press Release

"AOL is the leading online interactive services provider to the UK, with more than two million members"

I can't help thinking if they all show as USA users it is pretty pointless.

GeorgeGG

2:29 am on Jan 30, 2004 (gmt 0)

10+ Year Member



Also don't we have AOL in Germany, Australia and France?

GGG

brotherhood of LAN

2:35 am on Jan 30, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I've also downloaded/used the same list of IP's. Since it's not foolproof, you might want to offer the user an option along the lines of "click here if this is not your country" just so they are not hoodwinked into teh content/options you supplied with the wrong country.

operafan

3:41 am on Jan 30, 2004 (gmt 0)

10+ Year Member



But I've come across some products that claim that they are at least 95% close and offers auto updates on all the IP ranges. Do some search on mozzie (dmoz) & you can find some of vendors.
And it's best done server side or with programming to interface with the database of IP to redirect the users.

brotherhood of LAN

4:25 am on Jan 30, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



95% is still 1 in 20 being redirected to the wrong page :)

Is there really going to be a 100% 'hit the nail on the head' solution to mapping an IP to a country....

DrDoc

6:51 am on Jan 30, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



They can't help but show the US IP since AOL users get routed through a US gateway... And that's the IP that will show. If you don't want that to be the case -- get a different ISP :)

christodd

11:30 pm on Jan 31, 2004 (gmt 0)

10+ Year Member



You can use mod_geoip for apache [maxmind.com]. They have a bunch of programs for doing this, though I can't find any in Javascript. You can use .htaccess files [bitesizeinc.net] to serve different pages depending on the region they visitor is in, or use SSI and environmental variables to display the value on the page.