Get Canonical Host Name for IP address in Java
Description
The following code shows how to get Canonical Host Name for IP address.
Example
// w ww . jav a2s .c o m
import java.net.InetAddress;
public class Main {
public static void main(String[] argv) throws Exception {
byte[] ipAddr = new byte[] { (byte)173, (byte)194, 33, 115 };
InetAddress addr = InetAddress.getByAddress(ipAddr);
String hostnameCanonical = addr.getCanonicalHostName();
System.out.println(hostnameCanonical);
}
}
The code above generates the following result.