Advanced Java Programming Practical 14

Question 1
Develop a program using InetAddress class to retrieve IP address of computer when hostname is entered by the user.
InetDemo.java
Java
				import java.io.*;
import java.net.*;

public class InetDemo
{
    public static void main(String args[])throws IOException
    {
        String hostname;
        DataInputStream din=new DataInputStream(System.in);
        System.out.println("Enter Host Name: ");
        hostname= din.readLine();
        InetAddress ia=InetAddress.getByName(hostname);
        System.out.println("Ip Address of "+hostname+" is "+ia.getHostAddress());
    }
}

			
Output

Leave a Comment

Your email address will not be published. Required fields are marked *