InetAddress: getAllByName(String name) : InetAddress « java.net « Java by API






InetAddress: getAllByName(String name)

 
/*
 * Output:
 *  
 */

import java.net.InetAddress;

public class MainClass {

  public static void main(String args[]) {
    try {

      // Get an address
      InetAddress ias[] = InetAddress.getAllByName("www.google.com");
      for (int i = 0; i < ias.length; i++) {
        System.out.println(ias[i].getHostName());
        System.out.println(ias[i].getHostAddress());
        byte bytes[] = ias[i].getAddress();
        for (int j = 0; j < bytes.length; j++) {
          if (j > 0)
            System.out.print(".");
          if (bytes[j] >= 0)
            System.out.print(bytes[j]);
          else
            System.out.print(bytes[j] + 256);
        }
        System.out.println("");
      }

    } catch (Exception e) {
      e.printStackTrace();
    }
  }
}
           
         
  








Related examples in the same category

1.InetAddress: getByName(String host)
2.InetAddress: getCanonicalHostName()
3.InetAddress: getHostAddress()
4.InetAddress: getHostName()
5.InetAddress: getLocalHost()
6.InetAddress: isReachable(int timeout)