Sample code for 30+ languages & platforms
Java

Resolve a Hostname to an IP Address

See more Socket/SSL/TLS Examples

Demonstrates Socket.DnsLookup, which resolves a hostname and returns one numeric IP address.

Background. A maxWaitMs of 0 waits indefinitely; a positive value bounds the wait. Resolved results may be served from Chilkat's process-wide DNS cache.

Chilkat Java Downloads

Java
import com.chilkatsoft.*;

public class ChilkatExample {

  static {
    try {
        System.loadLibrary("chilkat");
    } catch (UnsatisfiedLinkError e) {
      System.err.println("Native code library failed to load.\n" + e);
      System.exit(1);
    }
  }

  public static void main(String argv[])
  {
    CkSocket socket = new CkSocket();

    //  Resolve a hostname to a numeric IP address, waiting up to 5 seconds.
    String ipAddress = socket.dnsLookup("example.com",5000);
    if (socket.get_LastMethodSuccess() == false) {
        System.out.println(socket.lastErrorText());
        return;
        }

    System.out.println("Resolved IP address: " + ipAddress);
  }
}