0

I have a Servlet project developed using Tomcat 7.

My projects logic is that whenever a request comes from certain IP it responds to the same IP with a new instance of browser as an response.

When I run and test this application locally it works perfect and by the way my local working IP address will be something like this 10.52.xxx.xxx. So request has 10.52.xxx.xxx and response is given to 10.52.xxx.xxx and all happies

Now things looks perfect and I planned to deploy this project in a Server which has an IP addess of 172.32.xxx.xxx and I have completed deployment of the same.

Now the issue which I am facing is that when I try to make a request to the project in the server (172.32.xxx.xxx) from my network (10.52.xxx.xxx).

In my project I have code like

String ip = request.getRemoteAddr(); //gets request IP address to give a new instance of browser

Now the variable ip contains an IP address of 172.32.xxx.xxx. So my code will try to give a browser instance to 172.32.xxx.xxx which doesn't exist. It should ideally give the browser instance back to 10.52.xxx.xxx as this is from which it had received the request so it has to respond to this IP.

I know both Server and the client request are in different IP network but I would like to know all possible solutions to fix the same so that browser is given back to 10.52.xxx.xxx.

Any help highly appreciated.

Santhosh_Reddy
  • 274
  • 4
  • 18
  • place the client ip address in a request attribute and use that value instead of getRemoteAddr – awd Feb 05 '16 at 10:56
  • @awadheshv that will allow user to spoof the ip address – Balaji Krishnan Feb 05 '16 at 11:28
  • I don't want to make use of external server to get IP. even if I use I get some other IP than what I am looking for example in my cmd I see 10.52.xxx.xxx and using external services I get 152.35.xxx.xxx Which I am not expecting it @BalusC – Santhosh_Reddy Feb 05 '16 at 13:53
  • @BalusC I have checked the duplicate post and I don't see the client IP (10.52.xxx.xxx) available in the request header. I see an IP of "43.254.163.221" I tried with the following commands String ip = request.getHeader("X-Forwarded-For"); // output = "43.254.163.221" ip = request.getHeader("Proxy-Client-IP"); // output = null ip = request.getHeader("WL-Proxy-Client-IP"); // output = null ip = request.getHeader("HTTP_CLIENT_IP"); // output = null ip = request.getHeader("HTTP_X_FORWARDED_FOR"); // output = null ip = request.getRemoteAddr(); //output = 10.117.18.18 but not 10.52.xxx.xxx – Santhosh_Reddy Feb 06 '16 at 16:13

0 Answers0