Getting Country Code from Clients IP Address
843838Oct 26 2006 — edited Apr 1 2008I am trying to determine the country that a user is accessing a web application from.
I'm using the following:
try {
byte[] ip = request.getRemoteAddr().getBytes();
Locale locale = InetAddressLocator.getLocale(ip);
String country_code = locale.getCountry();
} catch (InetAddressLocatorException ex) {
ex.printStackTrace();
}
However, when I access the web application it correctly traps my IP address, but for some reason outputs a country code of US even though I have a UK IP address.
I am using the net.sf.javainetlocator package.
Anyone help?