File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSP and the fly likes Can I get the machine name or IP? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Can I get the machine name or IP?" Watch "Can I get the machine name or IP?" New topic
Author

Can I get the machine name or IP?

verduka fox
Ranch Hand

Joined: Jan 18, 2001
Posts: 178
I have a web application which runs on our company intranet. The application uses JSPs and JavaBeans (no EJBs) and runs on WebSphere App Server version 4.0.3. I would like to know if it is possible to get the machine name or IP of the pc that is used to access the application. I would like to store the machine name or IP in the database in our audit log. I don't know if this is allowed due to security issues. Can anyone please comment and let me know if this is possible? I appreciate any direction that you can give me. Thanks.
Matthew Phillips
Ranch Hand

Joined: Mar 09, 2001
Posts: 2676
The ServletRequest interface has a method to get the IP address (getRemoteAddr) and a method to get the host name (getRemoteHost).


Matthew Phillips
Jeya Balaji
Ranch Hand

Joined: Jan 02, 2003
Posts: 40
Checkout these methods of request :
request.getRemoteAddr();
request.getRemoteHost();

Regards,
Balaji


Regards, Balaji
Marty Hall
Author
Ranch Hand

Joined: Jan 02, 2003
Posts: 111
As Matthew points out, you can use request.getRemoteAddr and request.getRemoteHost. However, don't forget that this information is not always as specific as you might want. The same PPP user will probably have a different IP address each time they dial in, and different corparate users could have the same address if they use a proxy (same goes for multiple different users on a shared system like a big Unix box).
- Marty


Java training and consulting
verduka fox
Ranch Hand

Joined: Jan 18, 2001
Posts: 178
Thanks for responding.
I have tested your suggestions: request.getRemoteAddr() and request.getRemoteHost() return the same value. What is the difference between the two? Should they be returning the same value?
My web app runs on our intranet, as well as having remote access from the internet. Would either of these methods give me a unique identifier?
Thanks again for your help.
verduka fox
Ranch Hand

Joined: Jan 18, 2001
Posts: 178
Can someone please address my concerns listed above? I appreciate your help!
Greg Charles
Sheriff

Joined: Oct 01, 2001
Posts: 2851
    
  11

Both getRemoteAddr() and getRemoteHost() start with the same information, but getRemoteHost() will try to resolve the IP Address to a host name. If it can't resolve the address, or chooses not to try for performance reasons, then it also returns the IP address.
I'm not sure what you mean by a unique identifier. Both methods return different views of the same thing, not fundamentally different information.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Can I get the machine name or IP?