Java Practical No 23
Java Practical No 23
Title Code:
import java.net.InetAddress;
public class HostnameIPRetriever {
public static void main(String[] args) {
try {
InetAddress address = InetAddress.getLocalHost();
System.out.println("Hostname: " + address.getHostName());
System.out.println("IP Address: " + address.getHostAddress());
} catch (Exception e) {
System.out.println("Error retrieving hostname and IP address: " +
e.getMessage());
}
}
}
O/P:
O/P:
O/P: