This post shows how to perform a nslookup in Java using InetAddress class.

This is possible due to the class java.net.InetAdress. We can instantiate it through the static method getByName() starting from an hostname and lookup the IP using the method getHostAddress().

try {

	InetAddress inetHost = InetAddress.getByName("google.com");
	String hostName = inetHost.getHostName();
	System.out.println("The host name was: " + hostName);
	System.out.println("The hosts IP address is: " + inetHost.getHostAddress());

} catch(UnknownHostException ex) {

	System.out.println("Unrecognized host");
}

ciao