InetAddressDemo.java

See InetAddress documentation

Wikipedia reference IP Address


// Demonstrate InetAddress.

import java.net.*;

class InetAddressDemo {

  public static void show(String arg) {
     try {
	 InetAddress address = InetAddress.getByName(arg);
	 System.out.println("Host name: " + address.getHostName());
	 System.out.println("Address: " + address.getHostAddress());
     }
     catch (UnknownHostException exc) {
	 System.out.println(exc);
     }
     System.out.println();
  }

  public static void main(String[] args) {

      show("www.mcgraw-hill.com");
      show("www.johnloomis.org");
      show("www.betelegeuse.org");
      show("www.udayton.edu");
  }
}


Results

Host name: www.mcgraw-hill.com
Address: 204.8.135.3

Host name: www.johnloomis.org
Address: 208.109.138.55

java.net.UnknownHostException: www.betelegeuse.org

Host name: www.udayton.edu
Address: 131.238.72.74


Maintained by John Loomis, updated Wed Nov 14 13:10:03 2012