ip address to country
Sigþór Hrafnsson <[email protected]>
| Newsgroups | gmane.comp.web.webobjects.devel |
|---|---|
| Message-ID | <[email protected]> |
Hi all
Just wanted to share some info. For those of you that want to map a ip
address to a country there is a database that
is able to to this i.e. http://ip-to-country.webhosting.info/node/view/5
I just created a deamon that is connected to a DB I populated with
ip-to-country codes, now when a user visits my site I can always
check to see what country he is coming from. At the moment I'm using this
for the logs, but it can be used for other
tasks as well.
To make a property list of the thing:
NOTE: sed and awk: direct the output to file rather that terminal output,
since this DB is quite large, about 4 MB.
The list comes in a excel file, save it to text and run the following sed
(s/\"//g) on it and direct the output to another file.
Put the following awk script in a file and run it on the output from the
sed, direct the output to a new file.
BEGIN { FS = "," }
{ print "{ " $1 " = " "( " "\""$1"\", " "\""$2"\", " "\""$5"\" ); }," }
Here I'm only using the high and low country codes and the full country
name. Direct the output to file. In the output
file put () around everything and delete the last comma. Now you have a
property list of the whole thing that can easily
be used to populate a DB.
Sigthor