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?
Use an IP lookup tool Starting with the simplest way to find someone's IP address is to use one of the many IP lookup tools available online. Resources such as WhatIsMyIPAddress.com or WhatIsMyIP.com offer tools to enter an IP address and search for its free public registry results.
How Easy Is It to Trace an IP Address? Tracing an unprotected IP address is as simple as a single line in the command prompt. However, if someone has hidden or obscured their IP with a decent VPN service, you'll just receive an error and get no information.
I went ahead with
HttpServletRequest request = (HttpServletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest(); String ipAddress = request.getHeader("X-FORWARDED-FOR"); if (ipAddress == null) { ipAddress = request.getRemoteAddr(); } System.out.println("ipAddress:" + ipAddress);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With