InetAddress
class which provides methods to get information about the network address of the local or remote hosts. import java.net.InetAddress;
public class IPAddressExample {
public static void main(String[] args) {
try {
InetAddress ip = InetAddress.getLocalHost();
System.out.println("IP address of the local system is: " + ip.getHostAddress());
} catch (Exception e) {
System.out.println(e);
}
}
}
IP address of the local system is: 10.8.25.52
InetAddress
class. We then use the getLocalHost()
method of the InetAddress
class to get the IP address of the local system. getHostAddress()
method of the InetAddress
class.