import java.net.*; public class InetAddressExample { public static void main(String[] args) throws UnknownHostException { InetAddress address = InetAddress.getLocalHost(); System.out.println("Localhost Address: " + address.toString()); } }
import java.net.*; public class InetAddressExample { public static void main(String[] args) throws UnknownHostException { String url = "www.google.com"; InetAddress[] addresses = InetAddress.getAllByName(url); for (InetAddress address : addresses) { System.out.println(url + " IP Address: " + address.toString()); } } }In this example, the getAllByName() method is used to obtain the IP addresses for a given URL (in this case, www.google.com). The toString() method is used to obtain the string representation of each IP address. The output will be a list of IP addresses associated with the URL. Package Library: The java.net.InetAddress class is part of the core Java library, which means it is included in the standard Java installation and does not require any additional packages or libraries.