• 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

how can i get client IP?

 
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I want to get client's IP address when it log in into the system. I am using request.getRemoteAddr() but it returns server's IP address instead of client's IP. I also tried request.getHeader("X-FORWARDED-FOR")

but it returns null. Now how can i get client IP?

Thanks in advance.
 
Saloon Keeper
Posts: 27764
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can't. Not reliably. All the clients on my backend LAN, for example have the apparent IP address of 216.199.14.19, but that's not their real IP addresses. They use addresses from the private (non-unique range), but pass through a NAT router, which assigns a fixed public address.
 
suchit pandya
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If its true then i will have to revert this application from client side. It is working fine at our testing servers and at our developement center but at cliet side it gives same addresses........
 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

getting a client IP in an application running behind load balancer is not possible. most of the time you will get the same IP address and cannot distinguish between the users.
Try this URL : http://whatismyip.com/ and see the ip you get and what is in the end logged in the web servers/ load balancer logs..

What are you trying to achieve here ?? may be i can help you with and alternative approach ?
 
Ranch Hand
Posts: 2187
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
[url]

I want to get client's IP address....

[/url]

This sounds very dubious ...
 
suchit pandya
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks all you guys for replying
and for NIV actually i store ip address of client when he login into my system and i made a report which gives information to user of Ip address and login time for each and every login made in system But right now it is showing same ip for all records.
 
Ranch Hand
Posts: 1871
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi

If you are testing within your LAN then mostly it will give you different IP, because the request is never out of your network.

However if you are testing from a specific client in a different network to a server in your network the IP will that be of your client proxy server even if different client machines are used.

You need to understand Network Address Translation in this case.

I dont see a reason as to why even if you could you would want to record the IP's of the local LAN which could change if the LAN has DHCP.

Now you need to state if this is ok from requirements perspective.


Br
Rahul
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic