Eran Medan Eran Medan - 1 year ago 90
Java Question

How to get the Node's server IP behind a load balancer in Java

I have a webpage behind a load balancer, and I want to display the user (for troubleshooting purposes) the IP of the actual node that the user is connected to (will be the same for a while due to sticky session)

I'm sure it's a very trivial question, but I want to be sure, what Java API should be used for that? will all APIs return me the request host? or will it be server dependent?

Answer Source

InetAddress.getLocalHost().getHostName() will give you the name of the server you are on. InetAddress.getLocalHost().getHostAddress() will give the IP Address of the server you are on.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download