Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Obtain FQDN in Java

I am trying to obtain the FQDN of a windows machine in my domain, using Java code.

I have tried the InetAddress.getByName("machine-1").getCanonicalHostName() but only returns the machine name.

On the other hand if I ping "machine-1" I get the fully domain name.

Do you know how to do it?

like image 742
hgonzalez Avatar asked Sep 01 '11 11:09

hgonzalez


1 Answers

The simple answer is that what you suggest works if it can.

The API does state that it will return the FQDN if it can. This depends on the system configuration.

The code you post does work for me on a windows domain machine, but I can't say why it wouldn't for you.

If you are unable to alter the machine / domain configuration such that java can pick it up, and it is essential for your code to use that FQDN, you could resort to executing the ping command from java and parse the results at least as a temporary measure.

like image 106
extorn Avatar answered Oct 03 '22 09:10

extorn