0% found this document useful (0 votes)
19 views1 page

Ajp 14

Uploaded by

Zara Shaikh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views1 page

Ajp 14

Uploaded by

Zara Shaikh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

X.

Program Code
1. Execute the following code and write the output
CODE:
import java.io.*;
import java.net.*;
public class exp14_1
{
public static void main(String args[])
{
try
{
InetAddress ip= InetAddress.getByName("localhost");
System.out.println("Host Name: "+ip.getHostName());
System.out.println("IP Address: "+ip.getHostAddress());
}
catch(Exception e){System.out.println(e);}
}
}

Develop a program using InetAddress class to retrieve IP address of computer when


hostname is entered by the user.

CODE:
import java.util.*;
import java.net.*;
public class exp14_2
{
public static void main(String args[])
{
String hname;
Scanner s = new Scanner(System.in);
System.out.println("Enter host name ");
hname=s.nextLine();
try
{
InetAddress a= InetAddress.getByName("localhost");
System.out.println("Host Name & IP Address: "+a.toString());
System.out.println("Host Name: "+a.getHostName());
System.out.println("IP Address: "+a.getHostAddress());
}
catch(Exception e){System.out.println(e);}
}
}

You might also like