PR AJPA14
PR AJPA14
PRACTICAL NO : 14
ENROLLMENT NO : 2215770092
NAME: Vedraj Sanjay jagdale
X. Program Code –
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