Saturday, September 14, 2013

Networking : Lesson 04 - InetAddress class


Networking : Lesson 04 - InetAddress class

The java.net.InetAddress class represent an IP address.
This class provides methods to get the IP of any host name.

import java.net.InetAddress;
import java.net.UnknownHostException;

public class InetAddressClass {

       /**
       * @param args
       */
       public static void main(String[] args) {

            try {
                  InetAddress address =         InetAddress.getByName("educationjavacode.blogspot.com");

                  System.out.println("Host Name : " + address.getHostName());
                  System.out.println("Host Address: " + address.getHostAddress());
            } catch (UnknownHostException e) {
                  e.printStackTrace();
            }
      }
}


Host Name : educationjavacode.blogspot.com
Host Address: 74.125.236.42