aspose file tools*
The moose likes Servlets and the fly likes Determining IP address I'm being communicated over Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Determining IP address I Watch "Determining IP address I New topic
Author

Determining IP address I'm being communicated over

Mike Dahmus
Greenhorn

Joined: Mar 07, 2002
Posts: 29
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 mike@dahmus.org
Mike Dahmus
Greenhorn

Joined: Mar 07, 2002
Posts: 29
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
internet detective
Marshal

Joined: May 26, 2003
Posts: 29253
    
140

Mike,
If you don't mind having a slightly different application on the clusters, add a servlet filter to the bad clusters.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Determining IP address I'm being communicated over
 
Similar Threads
writing vector object to I/O
Internet Access
naive server ip connection question
Sending video streams to a remote computer
How to get Client's IP address in Servlet