0% found this document useful (0 votes)
9 views2 pages

PR AJPA14

The document contains a practical assignment from DKTE’s Yashwantrao Chavan Polytechnic, where the student Vedraj Sanjay Jagdale executes Java code to retrieve the hostname and IP address of 'localhost' using the InetAddress class. Additionally, it includes an exercise requiring the development of a program that retrieves the IP address of a user-specified hostname. The provided code snippets demonstrate the implementation and expected outputs for both tasks.

Uploaded by

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

PR AJPA14

The document contains a practical assignment from DKTE’s Yashwantrao Chavan Polytechnic, where the student Vedraj Sanjay Jagdale executes Java code to retrieve the hostname and IP address of 'localhost' using the InetAddress class. Additionally, it includes an exercise requiring the development of a program that retrieves the IP address of a user-specified hostname. The provided code snippets demonstrate the implementation and expected outputs for both tasks.

Uploaded by

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

DKTE’s Yashwantrao Chavan Polytechnic , Ichalkaranji

PRACTICAL NO : 14

ENROLLMENT NO : 2215770092
NAME: Vedraj Sanjay jagdale

X. Program Code –

Que Execute the following code and write theoutput


Code –
import java.io.*;
import java.net.*;
public class Pr14P
{ 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);
}
}
}
Output –

Vedraj jagdale
DKTE’s Yashwantrao Chavan Polytechnic , Ichalkaranji

XIII. EXERCISE –

Que. 1 Develop a program using InetAddress class to retrive IP address of computer when
hostname is entered by the user.
Code -
import java.net.*;
public class Pr14E {
public static void main(String[] args) {
try {
System.out.print("Enter a hostname: ");
String hostname = System.console().readLine();
InetAddress address =
InetAddress.getByName(hostname);
System.out.println("IPAddress for " + hostname + ": " + address.getHostAddress());
} catch (UnknownHostException e) {
System.err.println("Unknown Host: " +
e.getMessage());
}
}
}
Output –

Vedraj jagdale

You might also like