This week's book giveaway is in the OCAJP forum.
We're giving away four copies of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) and have Khalid A Mughal & Rolf W Rasmussen on-line!
See this thread for details.
Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Getting IP address of User

 
rudresh kumar
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HI,

I have an J2EE application running on websphere server, Is there a way to get to know from which IP address does user 'X' has logged in ?.

Suppose a helpdesk team wants to know from which IP address does user 'X' has logged in.
Thanks
 
Srinivas Godavarthy
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, we can get the ip address of the requested system in your application. If you are using any servlet in your appliction then from HttpServletRequest you can get the ip address...see the following code..

public class TestServlet extends HttpServlet {
public void doGet (HttpServletRequest req,
HttpServletResponse res)
throws ServletException, IOException
{
PrintWriter out = res.getWriter();
String host = req.getRemoteAddr();
out.println("Hellow Your System IP is " + host);
out.close();
}
}
 
Rahul Bhattacharjee
Ranch Hand
Posts: 2308
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Srinivas Godavarthy:
Hi, we can get the ip address of the requested system in your application. If you are using any servlet in your appliction then from HttpServletRequest you can get the ip address...see the following code..

public class TestServlet extends HttpServlet {
public void doGet (HttpServletRequest req,
HttpServletResponse res)
throws ServletException, IOException
{
PrintWriter out = res.getWriter();
String host = req.getRemoteAddr();
out.println("Hellow Your System IP is " + host);
out.close();
}
}


the above code would give the IP of the last proxy that the request is passing through.It would only give the required result if there are no proxy between the server and the client.
 
RockyDude
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Suppose a helpdesk team wants to know from which IP address does user 'X' has logged in.


Try this out:
http://www.getfreesofts.com/script/548/23426/Display_IP_address_script_using_SSI_and_JavaScript.html
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65110
89
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"RockyDude",

There aren't many rules that you need to worry about here on the Ranch, but one that we take very seriously regards the use of proper names. Please take a look at the JavaRanch Naming Policy and adjust your display name to match it.

In particular, your display name must be a first and a last name separated by a space character, and must not be obviously fictitious.

Thanks!
bear
JavaRanch Sheriff
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic