InetAddress class represents an Internet Protocol (IP) address. We use the method named getHostAddress() of this class to get the IP address string in textual presentation.
Here is the source code of the Java Program to Display the IP Address of the System. The Java program is successfully compiled and run on a Windows system. The program output is also shown below.
public class IP_Address
public static void main(String args) throws Exception
InetAddress IP = InetAddress.getLocalHost();
System.out.println("IP of my system is := "+IP.getHostAddress());
$ javac IP_Address.java $ java IP_Address IP of my system is := 127.0.1.1
Sanfoundry Global Education & Learning Series – 1000 Java Programs.