java.net.InetAddress example

27 June 2008

Each computer on internet is called a node or a host. Each host has unique address called Internet Protocol (IP) address. IP addresses are not easy for the humans to remember therefore, Domain Name System (DNS) was introduced. DNS assigns a human understandable name to IP addresses.

InetAddress class represents IP addresses which can be useful in networking environment. Let see what we can o with this one:

Following code finds and prints the IP address of a given web host. Please note that some hosts have more than one IP addresses therefore, we will get all the IP addresses in an array and then will print those.

try {
InetAddress[] addresses =
InetAddress.getAllByName("www.cnn.com");
for (int i = 0; i < addresses.length; i++) {
System.out.println(addresses[i]);
}
}
catch (UnknownHostException ex) {
System.out.println("Could not find the host.");
}

Related Posts:

  • No related posts
del.icio.us:java.net.InetAddress example  digg:java.net.InetAddress example  spurl:java.net.InetAddress example  wists:java.net.InetAddress example  simpy:java.net.InetAddress example  newsvine:java.net.InetAddress example  blinklist:java.net.InetAddress example  furl:java.net.InetAddress example  reddit:java.net.InetAddress example  fark:java.net.InetAddress example  blogmarks:java.net.InetAddress example  Y!:java.net.InetAddress example  smarking:java.net.InetAddress example  magnolia:java.net.InetAddress example  segnalo:java.net.InetAddress example  gifttagging:java.net.InetAddress example

Top Of Page | Trackback

If you found this page useful, consider linking to it. Simply copy and paste the code below into your web site.

It will look like this: java.net.InetAddress example

Leave a Reply