topr8 - 12:10 am on Dec 31, 2010 (gmt 0)
you need a database that matches ip's to countries, there are free ones available, you then have to keep it up to date, as it changes.
you then compare the user ip to the database and extract the country - pretty simple.
i'm not sure of any ready made scripts that do this, i imagine a quick search on your favourite search engine for something like:
free country to ip database
would return some results