Java API Tutorial - Java InetAddress.getByName(String host)








Syntax

InetAddress.getByName(String host) has the following syntax.

public static InetAddress getByName(String host)    throws UnknownHostException

Example

In the following code shows how to use InetAddress.getByName(String host) method.

//  w w w  . java  2 s.c om
import java.net.InetAddress;

public class Main {

  public static void main(String[] args) {

    try {
      InetAddress ia = InetAddress.getByName("64.21.29.37");
      System.out.println(ia.getHostName());
    } catch (Exception ex) {
      System.err.println(ex);
    }

  }

}

The code above generates the following result.