• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Obtaining client ip address using Struts1.2

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


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.
 
Ranch Hand
Posts: 300
Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 300
Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
reply
    Bookmark Topic Watch Topic
  • New Topic