Java Program to Find hostname from IP Address


-

-

Example:

Copied
import java.net.InetAddress;
public class HostName {
    public static void main(String[] argv) throws Exception {
		InetAddress ipAddr = InetAddress.getByName("8.8.8.8");
		System.out.println("Host name: "+ipAddr.getHostName());
		System.out.println("Ip address: "+ ipAddr.getHostAddress());
	}
}

Output:

Host name: dns.google
Ip address: 8.8.8.8