*
The moose likes Struts and the fly likes Obtaining client ip address using Struts1.2 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Obtaining client ip address using Struts1.2" Watch "Obtaining client ip address using Struts1.2" New topic
Author

Obtaining client ip address using Struts1.2

jack hiren
Greenhorn

Joined: Sep 12, 2012
Posts: 6


I am supposed to capture the ip address of the client machine, who hits my web application.
After googling, I have found two ways :

1) request.getRemoteAddr()

2)request.getHeader("X-FORWARDED-FOR")

but both of them do not guarantee returning the actual ip of the client machine.
Also, I am supposed to achieve the same using struts1.2, as the application is developed in struts1.2.

Is there any struts class for the same?

This is an urgent requirement and i am stuck on it for long.
please help.

Thanks.
jatan bhavsar
Ranch Hand

Joined: Jul 23, 2008
Posts: 296

Hi hiren,

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.

Regards
jatan
jack hiren
Greenhorn

Joined: Sep 12, 2012
Posts: 6
Heyy jatan...,

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.

Any help on this.

Urgent..
Please help..
Thanks
jatan bhavsar
Ranch Hand

Joined: Jul 23, 2008
Posts: 296

Hi hiren,

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.



Regards
jatan
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Obtaining client ip address using Struts1.2
 
Similar Threads
How to get IP Address of Client Machine?
How to obtain the destination machine information
Data corruption while using I/O streams and sockets in Java
IP address keeps changing
Data corruption using Sockets in Java !!!