Get IP address of Website using InetAddress

Java example to get IP address of Website using InetAddress:

package javainetaddress;

import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
*
* @web http://java-buddy.blogspot.com/
*/
public class JavaInetAddress {

public static void main(String[] args) {
try {
InetAddress inetAddress = InetAddress.getByName("www.google.com");
System.out.println(inetAddress);
System.out.println(inetAddress.getHostName());
System.out.println(inetAddress.getHostAddress());
} catch (UnknownHostException ex) {
Logger.getLogger(JavaInetAddress.class.getName()).log(Level.SEVERE, null, ex);
}
}

}


Source: http://java-buddy.blogspot.com/

Be the first to comment

Leave a Reply

Your email address will not be published.


*