[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

How can i get the IP Address of a request

Posted on 2011-05-04
9
Medium Priority
?
377 Views
Last Modified: 2012-05-11
HI

In my environment we have "Apache Server"-> WebDispatcher->Web  Application Server.
In my JSP which is running on Web AS i want to get the IP Address of the User who enters the URL on any of the client machine.

I'm using:
var ip =  '<%=request.getRemoteAddr()%>';
to get the IP Address . Problem which i'm facing is due to this i'm getting the IP Address of Web Dispatcher, as Web Dispatcher is sending request to this URL .

I want to get the IP Address of the Actual User.

How can i get the IP address of the USer.

Thanks
Puneet
0
Comment
Question by:PuneetKSaxena
  • 3
  • 2
  • 2
  • +2
9 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 35688597
You might not be able to do so. What would you do with it if you had it?
0
 
LVL 92

Expert Comment

by:objects
ID: 35688598
it may not be available
display the contents of the request header to see whats being passed to you.
Sounds like its getting lost at the dispatcher
0
 

Author Comment

by:PuneetKSaxena
ID: 35688605
Based on IP Address of the User i need to do some operation.

Please suggest any other solution.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 20

Expert Comment

by:Sathish David Kumar N
ID: 35688608
InetAddress.getLocalHost().getHostAddress()
0
 
LVL 20

Expert Comment

by:Sathish David Kumar N
ID: 35688616
you need to import java.net.*; in ur JSp
0
 

Author Comment

by:PuneetKSaxena
ID: 35688640
This will give me IP Address of Web Dispatcher which is finally sending the request to the Web AS
0
 
LVL 47

Accepted Solution

by:
for_yan earned 2000 total points
ID: 35688651




http://www.coderanch.com/t/293684/JSP/java/client-IP-address-Domain-JAVA
Joined: Feb 20, 2002
Posts: 107
      
posted Tuesday, June 03, 2008 10:24 PM private message
0
Quote
getRemoteAddr, getRemoteHost and getRemotePort of ServletRequest returns details of the client calling the services. It can be the end client (request made directly from the client to server) or proxy (If there are proxy servers or NATting firewalls between your web server or servlet engine and the end users)

Of course you can get proxy in most cases
0
 

Author Closing Comment

by:PuneetKSaxena
ID: 35688749
This links helped me

I tried

    String ipAddress  = request.getHeader("X-FORWARDED-FOR");  
        if(ipAddress == null)  
        {  
          ipAddress = request.getRemoteAddr();  
        }  

and that gave me proper IP

Thanks
Puneet
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 35688791
Make sure you know the full chain from Apache inwards. What other software is there (e.g. which servlet container)?
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

During and after that shift to cloud, one area that still poses a struggle for many organizations is what to do with their department file shares.
This article will show you step-by-step instructions to build your own NTP CentOS server.  The network diagram shows the best practice to setup the NTP server farm for redundancy.  This article also serves as your NTP server documentation.
After creating this article (http://www.experts-exchange.com/articles/23699/Setup-Mikrotik-routers-with-OSPF.html), I decided to make a video (no audio) to show you how to configure the routers and run some trace routes and pings between the 7 sites…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
Suggested Courses
Course of the Month18 days, 1 hour left to enroll

829 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question