Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Finding user ip address

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?

like image 358
Fahim Parkar Avatar asked Sep 07 '12 19:09

Fahim Parkar


People also ask

How can I find someone's IP address?

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.

Is it easy to find out someone's IP address?

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.


1 Answers

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); 
like image 159
Fahim Parkar Avatar answered Oct 26 '22 04:10

Fahim Parkar