This week's book giveaways are in the Jython/Python and Object-Oriented programming forums.
We're giving away four copies each of Machine Learning for Business: Using Amazon SageMaker and Jupyter and Object Design Style Guide and have the authors on-line!
See this thread and this one for details.
Win a copy of Machine Learning for Business: Using Amazon SageMaker and JupyterE this week in the Jython/Python forum
or Object Design Style Guide in the Object-Oriented programming forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Paul Clapham
  • Jeanne Boyarsky
  • Knute Snortum
Sheriffs:
  • Liutauras Vilda
  • Tim Cooke
  • Junilu Lacar
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Joe Ess
  • salvin francis
  • fred rosenberger

How can I resolve the IP address of a PC into the location of that PC

 
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello everyone,
I'm currently building a website and I want to include an Applet that would display the visitors IP address, the name of thier PC and their locale (Where they are logging in from) and thier username on the PC machine they are logging in on. Now I have done the first two, but I am having problems with the last two and I need help here.
Now I achieved the first two using:
For the first: return InetAddress.getLocalHost().getHostAddress();
and return InetAddress.getLocalHost().getHostName(); for the second.
Does anyone know of a way to get the Locale of the user or to resolve the IP address into something useful, like the location in which the applet is running? Also, does anyone know how to get the username of the user?
I am entirely sure these things are possible, moreso when the applet runs completely on the client machine and the location of the computer is fed in at installation.
Any useful suggestions would be appreciated.

Thanks.
 
Ranch Hand
Posts: 189
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by Femi Alla:
I want to include an Applet that would display the visitors IP address, the name of thier PC and their locale (Where they are logging in from) and thier username on the PC machine they are logging in on.


I wouldn't really favor an applet for doing these things, as they are best accomplished on the server side. Of course, that may not be an option if you are not allowed do server side code.
That being said, you can call Locale methods in your applet to get the Locale info,

According to the API for java.util.Locale, this will get you, "the current value of the default locale for this instance of the Java Virtual Machine" and "a name for the locale's country that is appropriate for display to the user" respectively.
Of course, this has nothing to do with the IP address that the HTTP request originates from, so it may not be what you are looking for.
If you want information that is derived from IP address lookups, this is best done on the server side, and then passed to the applet as a parameter. You won't know enough about the requestor's environment to be of much use on the client side, and the JVM security model greatly limits your options.
As to knowing the user's name (uid), I have to ask: what if they are using a Mac or a Win95/98/Me PC that doesn't require them to log in? There may not be a meaningful user ID available. And even if there is, the JVM security model should block your access to it (unless you are going to get into signed applets and all that).
Your best bet again is on the server side. If the user provides a user name or ID via a form, you can pass that as a parameter into your applet, save it in a cookie or in a Servlet environment as a Session property.
Hope this helps!
PCS
 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i think to get the ip address ,we can use :
HttpRequet.getClient().getInetAddress().getHostAddress()
to get the client ip address
then with the method System.getProperty(''os.name'') and System.getProperty(''os.arch''),we can get the informations of the client os.
 
Philip Shanks
Ranch Hand
Posts: 189
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Two things:
First, I don't think that "cer" is a valid username in this forum, and you will probably get scolded for it by one of the moderators.
Second, I don't believe that HttpRequest is a valid client side object (I know that it does not exist in the Java 1.4 API). You may be referring to a class called javax.servlet.http.HttpServletRequest, which is available in J2EE Servlet containers such as Tomcat.
If you wish to pursue the server-side option, here is (briefly) how you might approach it in a servlet:

In a JavaServer Page you have the implicit object named "request", which extends javax.servlet.ServletRequest, which is where the getRemoteAddress() method comes from.
You could have a line like,

PCS
[ November 06, 2002: Message edited by: Philip Shanks ]
 
Grow your own food... or this tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!