0

In our private network. We have physical host name (x.mycompany.com) and dns resolvable (x1.mycompany.com) virtual host name configured to the actual physical host name.

How in java, I can verify if they both inturn resolve to same?

Virtual host has it's own IP address which is different to physical host. So I can't compare the IP address to check if they both are same.

Any help is appreciated. Thanks.

  • `InetAddress.getLocalHost()`? Note that unlike what its name seems to suggest, this will _not_ return `localhost`; it returns the "main" name of the machine as defined at the OS level – fge Mar 21 '14 at 07:26
  • @fge - we already know that the host has two different IP addresses. – Stephen C Mar 21 '14 at 07:34

1 Answers1

0

Assuming that:

  1. the host's network interfaces are configured for all of its IP addresses, and

  2. you are running the "test" code on the host itself,

then you can resolve the hostnames to IP addresses, and compare them against all of the addresses bound to the NetworkInterface objects returned by NetworkInterface.getNetworkInterfaces().

If either of those assumptions is incorrect, then I don't think there is an easy way to do this.

Stephen C
  • 698,415
  • 94
  • 811
  • 1,216