In Java, you can use InetAddress.getLocalHost()
to get the Ip Address of the current Server running the Java app.
package com.favtuts.tests; import java.net.InetAddress; import java.net.UnknownHostException; public class ServerIPaddress { public static void main(String[] args) { InetAddress ip; try { ip = InetAddress.getLocalHost(); System.out.println("Current IP address : " + ip.getHostAddress()); } catch (UnknownHostException e) { e.printStackTrace(); } } }
Output
Current IP address : 192.168.1.22
Download Source Code
$ git clone https://github.com/favtuts/java-core-tutorials-examples
$ cd java-misc/tests