• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Advanced question (I think)

 
clojure forum advocate
Posts: 3479
Mac Objective C Clojure
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi ranchers.
I want to develope a servlet that can know the IP of the client and determin to which country he is belong.
I am thinking to specify the proxy name (if possible) , so if it is ends with uk so the user from england and so on....
any ideas ...
 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There is an accept-language header which forms part of HTTP. From this you can get the prefered Locale of the client, presuming the request includes this header. Of course there is not guarentee the Locale a user sets their machine to maps to the actualy country they are in.
 
Ranch Hand
Posts: 5093
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The first part (retrieving the IP address) is easy, just call "getRemoteAddr()" on the request.
The second part is tricky to say the least.
There is no real geographic split in IP addresses anymore. Though in theory blocks are assigned to regional entities this doesn't suffice for your purpose as there are super-regional customers to those entities.

For example, AOL may request a range of IP addresses from the US pool and assign those to German customers. If you used the pool from which they are drawn as a basis you'd class that German as an American.
The pools are also not fine-grained enough for your purpose. All of Europe shares a single agency for handing out blocks for example.

More information on IP assignments: http://www.ripe.net/ripencc/about/regional/

You could try a whois lookup on the number and try to determine where it is assigned to.
But that still would not necessarilly resolve scenarios where an IP address is assigned to a company in one country but used by a computer located in another.
 
Jeroen Wenting
Ranch Hand
Posts: 5093
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Paul Sturrock:
There is an accept-language header which forms part of HTTP. From this you can get the prefered Locale of the client, presuming the request includes this header. Of course there is not guarentee the Locale a user sets their machine to maps to the actualy country they are in.



none at all indeed.
For example I'm definitely not in the USA or UK but I have my preferences set to UK English first, US English second and Dutch third.
That would make
EN_en
EN_uk
EN_us
NL_nl
NL_be
I think I send German (DE_de, DE_at) as well.

Most people never change those settings at all, and unless they have a localised OS and browser for not just their language but country incorrect data will be returned.
 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try MaxMin GeoIP
I haven't played around with it, but it's got a java api and free download.

You can see it in action at the at:MySql downloads page

Of course, this is IP is not guaranteed to be accurate, as per the posts above.
 
Ranch Hand
Posts: 236
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
To translate an IP address to a host name, you need to do a "reverse lookup". The sockets API to do this is:
gethostbyaddr ()

If the resulting TLD is something like ".uk" or ".de", then you're in luck. Otherwise, you'll have to fall back on some other method (like parsing the language info in the HTTP header).

Hope that helps .. PSM
 
reply
    Bookmark Topic Watch Topic
  • New Topic