Reputation: 36452
I have to find whether two servers are running in same host.
I have two hosts but I can't compare them since one can have an ip address and the other may have a hostname. When I dug further I found there can be any number of aliases for a hostname. So how can I find out if two host aliases (where one can be an IP) correspond to same host or different host?
We can find the hostname using java.net.InetAddress.getLocalHost().getHostName();
but I am not sure how to find if two hostnames are pointing to same host?
Upvotes: 1
Views: 645
Reputation: 3749
Do an NSlookup of the two host names. Compare results.
You can use InetAddress.getHostAddress() to perform the lookup.
Note that the host names may be behind a load balancer or other type of proxy, so there is no reliable way to test if they're actually "running on the same (physical) machine".
Upvotes: 0
Reputation: 917
InetAddress::getByName()
]NetworkInterface::getByInetAddress()
]NetworkInterface::getHardwareAddress()
]Upvotes: 0
Reputation: 326
You could convert everything to an IP Address and, since we know these are unique, compare those together.
Have a look at this article.
http://www.java2s.com/Code/Java/Network-Protocol/ConvertahostnametotheequivalentIPaddress.htm
Upvotes: 1