Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Getting Country Code from Clients IP Address

843838Oct 26 2006 — edited Apr 1 2008
I 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?
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Apr 29 2008
Added on Oct 26 2006
6 comments
519 views