Friday, April 27, 2012

DNS Lookup in Java

A simple DNS lookup in Java
import java.net.InetAddress;
import java.net.UnknownHostException;

public class DNSLookup {
    
    public static void main(String... args) {
        InetAddress inet = null;
        try {
            final String host = "eradicus.blogspot.com";
            inet = InetAddress.getByName(host);
            System.out.println("DNS Lookup: " + host);
            System.out.println("IP Adress: " + inet.getHostAddress());
        } catch (UnknownHostException e) {
            e.printStackTrace();
        }
    }
}
By using the InetAddress API you will be able to obtain the IP address of the target.

No comments: