This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
Refer this Thread it has all the discussion about getting client IP address.
to get the IP from client you can use this one
X-Forwarded-For (XFF) HTTP header is a stadandard to identify ip address of a client which comes from the proxy but if it is coming directly from client then it might return null so we have put the condition and whenever it dosent come from proxy we will get the clients ip directly.
Joined: Sep 12, 2012
Thanks for the help mate...1!!
but there's an problem, i am deploying my application on a public ip.
the method request.getHeader("X-FORWARDED-FOR") is returning NULL, further to which i am getting ip from method request.getRemoteAddr() as suggested by you, when i am hitting from any mobile device or wireless internet medium like Tata photon or MTS, As a result of which, private ip of the device is displayed and not the public ip which is needed by me.
Also, I'm not able to retrieve the public ip when the client machine is in hardware based firewall.
From my point of view you cant get the public ip of the mobile device as operators does some address translation and expose only single ip which will be common for all the users. Basically its routers ip which is exposing as public ip not the particular mobile users ip.