You have two choices effectively. The first choice is to use a web service to look up the country based on the IP address, but most services charge for usage as they are commercial offerings. The second option is to use
Webnet77[
^] to download the IP address ranges and maintain them yourself. You can then match the data based locally.