Tuesday, March 1, 2016

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);
        }
    }
    
}




No comments:

Post a Comment