Wednesday, October 5, 2016

a java program to prompt the user for a hostname and then looks up the IP Address for the hostname and displays the results



Aim: Write a java program to prompt the user for a hostname and then looks up the IP Address for the hostname and displays the results.

Program:

       import java.lang.*;
import java.util.*;
import java.net.*;
class Address
{
   public static void main(String args[])
     {
        try
         {
            String a=args[0];
            InetAddress i=InetAddress.getByName(a);
            System.out.println(""+i.getHostAddress());
          }
       catch(Exception e)
     {
       System.out.println("Exception caught");
     }
}
}

Output:


Labels:

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home