InetAddress: getCanonicalHostName() : InetAddress « java.net « Java by API






InetAddress: getCanonicalHostName()

  

import java.net.InetAddress;

public class Main {
  public static void main(String[] argv) throws Exception {
    InetAddress addr = InetAddress.getByName("127.0.0.1");
    byte[] ipAddr = new byte[] { 127, 0, 0, 1 };
    addr = InetAddress.getByAddress(ipAddr);
    // Get the host name
    String hostname = addr.getHostName();
    // Get canonical host name
    String canonicalhostname = addr.getCanonicalHostName();

  }
}

   
    
  








Related examples in the same category

1.InetAddress: getAllByName(String name)
2.InetAddress: getByName(String host)
3.InetAddress: getHostAddress()
4.InetAddress: getHostName()
5.InetAddress: getLocalHost()
6.InetAddress: isReachable(int timeout)