• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Determining IP address I'm being communicated over

 
Mike Dahmus
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have code running on the server in a login servlet - in the case which is causing concern we're using a clustering solution which results in multiple IP addresses being active (on different interfaces) for the same machine. One is the 'normal' address and one is the 'cluster'. (i.e. one machine at a time 'owns' the cluster address).

For various reasons, I need to know which IP address is being used on a given servlet call. (i.e. the machine's normal eth0 address is 1.1.1.1, and it also has an eth0:0 address of 3.3.3.3 (cluster); the servlet needs to know which one is being used for the current HTTP activity so I can potentially tell them "don't log in here; log in there instead").

getServerName() works somewhat - but provides a hostname if the user had connected that way from the client. That makes me unsure that this is even going to work for the case I'm concerned about. Basically we used to do this on the client side but discovered that the NAT case doesn't work with this (where the servers are behind a NAT and thus the client can't compare what it sees in a well-known spot on the server against its own settings, since the client's versions of the addresses aren't the same).

Any suggestions?

Thanks,
Mike Dahmus
mdahmus@netbotz.com
 
Mike Dahmus
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
followup: I now see the method getLocalAddr() was added in Servlet 2.4. Unfortunately, I'm stuck for now with Servlet 2.3 (can't afford to upgrade our embedded Tomcat to 5 at this point - way too risky). Any hacks which can get me there on 2.3?
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34202
341
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mike,
If you don't mind having a slightly different application on the clusters, add a servlet filter to the bad clusters.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic