Reference data: ip-to-country

This WebDNA talk-list message is from

2004


It keeps the original formatting.
numero = 56863
interpreted = N
texte = > Does anyone have a foolproof way of determining the > country that a visitor to a website is viewing it from ? Hi Stuart, You're really going to like this solution, it is fast and simple, and if the db is accurate it is relatively foolproof. Others may like this one to, so I gave this post a new subject -- for the archives. The following web site offers a FREE csv file that has the current ip address ranges used in all the countries in the world: http://ip-to-country.webhosting.info/ I downloaded their "ip-to-country.csv.zip" file and extracted it, then I imported it into my desktop database program. I immediately deleted the field that holds the full country name ... because the field with the two-letter country abbreviation was good enough for me, I didn't need the full country name in my particular application. Then because I only want to identify visitors from one country, I deleted the records for all the other countries. This left me with a very slimmed down database of only the ip address ranges of the one country I want to check. Of course, by NOT removing any of the db records this technique could easily identify the visitor's location no matter what country he/she is in. Then I saved the results as a tab-delimited file to use with webdna. Since this db uses numeric representations of ip addresses I had to do some math in order to match the visitor's ip address with the values in the db. The web site explains how these ip range values are calculated, so it's a simple task to write the required math code. Nevertheless, I'm including it here for your convenience. Here's the code I use, it will work with your solution too, assuming that you name your db fields "ip1", "ip2" and "co": [math show=f]ipA=[getchars start=1&end=3][ipaddress][/getchars]*256*256*256[/math] [math show=f]ipB=[getchars start=5&end=7][ipaddress][/getchars]*256*256[/math] [math show=f]ipC=[getchars start=9&end=11][ipaddress][/getchars]*256[/math] [math show=f]ipD=[getchars start=13&end=15][ipaddress][/getchars][/math] [math show=f]ipValue=ipA+ipB+ipC+ipD[/math] [search db=ips.db&leip1datarq=[ipValue]&ip1type=num&geip2datarq=[ipValue]&ip2type=num] [founditems]visitor is in [co][/founditems] [showif [numfound]=0]visitor is somewhere else[/showif] [/search] If you use the entire db (instead of using the records of only one country like I did) you won't need the showif because the founditems will always show you the country the visitor is in. That's all there is to it, a solution that is as foolproof as it gets -- assuming you are willing to use ip addresses to identify the locations of your visitors. Just download a new copy of the csv file whenever you feel the need to update your database ... :) -- Kenneth Grome WebDNA Programmer Outsource Service Provider Phone: +6332 255-6591 ------------------------------------------------------------- This message is sent to you because you are subscribed to the mailing list . To unsubscribe, E-mail to: To switch to the DIGEST mode, E-mail to Web Archive of this list is at: http://webdna.smithmicro.com/ Associated Messages, from the most recent to the oldest:

    
  1. Re: Reference data: ip-to-country ( Mark Derrick 2004)
  2. Re: Reference data: ip-to-country ( Stuart Tremain 2004)
  3. Re: Reference data: ip-to-country ( Mark Derrick 2004)
  4. Reference data: ip-to-country ( Kenneth Grome 2004)
> Does anyone have a foolproof way of determining the > country that a visitor to a website is viewing it from ? Hi Stuart, You're really going to like this solution, it is fast and simple, and if the db is accurate it is relatively foolproof. Others may like this one to, so I gave this post a new subject -- for the archives. The following web site offers a FREE csv file that has the current ip address ranges used in all the countries in the world: http://ip-to-country.webhosting.info/ I downloaded their "ip-to-country.csv.zip" file and extracted it, then I imported it into my desktop database program. I immediately deleted the field that holds the full country name ... because the field with the two-letter country abbreviation was good enough for me, I didn't need the full country name in my particular application. Then because I only want to identify visitors from one country, I deleted the records for all the other countries. This left me with a very slimmed down database of only the ip address ranges of the one country I want to check. Of course, by NOT removing any of the db records this technique could easily identify the visitor's location no matter what country he/she is in. Then I saved the results as a tab-delimited file to use with webdna. Since this db uses numeric representations of ip addresses I had to do some math in order to match the visitor's ip address with the values in the db. The web site explains how these ip range values are calculated, so it's a simple task to write the required math code. Nevertheless, I'm including it here for your convenience. Here's the code I use, it will work with your solution too, assuming that you name your db fields "ip1", "ip2" and "co": [math show=f]ipA=[getchars start=1&end=3][ipaddress][/getchars]*256*256*256[/math] [math show=f]ipB=[getchars start=5&end=7][ipaddress][/getchars]*256*256[/math] [math show=f]ipC=[getchars start=9&end=11][ipaddress][/getchars]*256[/math] [math show=f]ipD=[getchars start=13&end=15][ipaddress][/getchars][/math] [math show=f]ipValue=ipA+ipB+ipC+ipD[/math] [search db=ips.db&leip1datarq=[ipValue]&ip1type=num&geip2datarq=[ipValue]&ip2type=num] [founditems]visitor is in [co][/founditems] [showif [numfound]=0]visitor is somewhere else[/showif] [/search] If you use the entire db (instead of using the records of only one country like I did) you won't need the showif because the founditems will always show you the country the visitor is in. That's all there is to it, a solution that is as foolproof as it gets -- assuming you are willing to use ip addresses to identify the locations of your visitors. Just download a new copy of the csv file whenever you feel the need to update your database ... :) -- Kenneth Grome WebDNA Programmer Outsource Service Provider Phone: +6332 255-6591 ------------------------------------------------------------- This message is sent to you because you are subscribed to the mailing list . To unsubscribe, E-mail to: To switch to the DIGEST mode, E-mail to Web Archive of this list is at: http://webdna.smithmicro.com/ Kenneth Grome

DOWNLOAD WEBDNA NOW!

Top Articles:

Talk List

The WebDNA community talk-list is the best place to get some help: several hundred extremely proficient programmers with an excellent knowledge of WebDNA and an excellent spirit will deliver all the tips and tricks you can imagine...

Related Readings:

form data submission gets truncated (1997) Order not created error (1997) seeminly simple... but beyond my grasp :) (2000) Summing fields (1997) NewCart+Search with one click ? (1997) Getting Emailer to send mail (1997) state? (2004) Nav. 4 probs with cart (1997) Re:no [search] with NT (1997) test (2006) WebDNA Quick Reference (Reserved Words) (2000) Re2: frames & carts (1997) I give up!! (1997) off topic - dna snipets (1997) Sorting Various Sizes (2003) Math with Time (1997) Solve the Problem, get the code! (2001) [shownext] and sort (1998) WebCatalog NT beta 18 problem (1997) presetting variables ... (2000)