• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Can I get the machine name or IP?

 
verduka fox
Ranch Hand
Posts: 178
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2676
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The ServletRequest interface has a method to get the IP address (getRemoteAddr) and a method to get the host name (getRemoteHost).
 
Jeya Balaji
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Checkout these methods of request :
request.getRemoteAddr();
request.getRemoteHost();

Regards,
Balaji
 
Marty Hall
Author
Ranch Hand
Posts: 111
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
verduka fox
Ranch Hand
Posts: 178
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 178
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can someone please address my concerns listed above? I appreciate your help!
 
Greg Charles
Sheriff
Posts: 2993
12
Firefox Browser IntelliJ IDE Java Mac Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic