If you need to make this server part, you will need to get one of the databases that display IP addresses in countries and cities. These databases are outdated and usually commercial. Maxmind has various licenses for its database, including some free ones that I consider.
However, if you can transfer the validation to the client side, in the browser you can make an ajax call to the Maxmind free JSONP API to get the estimated location of your user, and then let your application process the solutions using javascript.
source share