To get IP address of the current computer that’s running the Java application, uses InetAddress.getLocalHost() to initialize the InetAddress object and InetAddress.getHostAddress() to get the current IP address.

Full example.

Output

IP 192.168.0.185 is my computer’s IP address to run this example, let compare with Ubuntu’s ifconfig

ifconfig output…

Same, InetAddress.getHostAddress() is working as expected.