I have created web application using JSF 2.0. I have hosted it on hosting site and the server of the hosting site is based in US.
My client want the details of the user who all accessed the site. How can I find the IP address of user in JSF?
I tried with
try {
InetAddress thisIp = InetAddress.getLocalHost();
System.out.println("My IP is " + thisIp.getLocalHost().getHostAddress());
} catch (Exception e) {
System.out.println("exception in up addresss");
}
however this gives me ip address of my site only i.e. server ip address.
Could someone tell me how to get IP address who accessed the website using Java?
Try this...
I went ahead with
A more versatile solution
Improved version of the accepted answer that works even if there are multiple IP addresses in the
X-Forwarded-For
header: