The class java.net.InetAddress represents an Internet Protocol (IP) address. It has a static method, getLocalHost(), that you can use to obtain an instance of java.net.InetAddress based on your local machine's IP settings.
Then, use the getHostAddress() method of java.net.InetAddress class to obtain the IP address. The following code demonstrates this:
java.net.InetAddress localMachine =
System.out.println ("IP of local machine: " +