Tuesday, 14 March 2017

Java program to get list of all IPs of a given Host

import java.net.InetAddress;
import java.net.UnknownHostException;
 
public class MyAllIpAddresses {
 
    public static void main(String a[]){
     
        try {
            InetAddress[] myHost = InetAddress.getAllByName("www.google.com");
            for(InetAddress host:myHost){
                System.out.println(host.getHostAddress());
            }
        } catch (UnknownHostException ex) {
            ex.printStackTrace();
        }
    }
}

No comments:

Post a Comment