IPAddress to Country
How to know the Country from the IPAddress?
I want to know from which country is the client logging into my website, is there any process to do so. I think it is possible to know it from the IPAddress, but I don't know how to get started.. please help... :)
There are databases and services that can get it sort of correct. But its impossible to get it correct.
I worked for a multi-national company, and all of the computers in Dusseldorf, Germany, had IP addresses that were from the HQ located in Virginia, USA.
Google for IP geolocation
The most accurate way is to reference a pre-built database as @fishtoprecords says. Technically, you can often get the country information from the WHOIS database, but you're "not supposed to" for marketing purposes.
In practice, existing databases take their data from a variety of "clues":
- the WHOIS database (yes, naughtily, I'm fairly sure it is used -- look for IP addresses registered with British Telecom (BT) which the database mysteriously thinks is from the country of Bhutan)
- routing infomation -- looking to see if tracing to particular IPs passes through certain routers that are obviously in a particular country
- partnering with web sites that take user information and just ask the user what country they're in then associate it with their IP address
Another approach that is less accurate but doesn't require a database is to just look at the country of the search engine from which the user got to your site. I put together a page a while back on geolocation from the referer string, with examples of specific regular expressions that work with the main search engines. A surprising number of users actually are quite patriotic and use a search engine for their country. In a few cases, this approach actually distinguishes better than some databases, which have trouble with companies using routers across each other's borders (AOL connections in the UK/France were reckoned to be a particular problem at one point I seem to recall).