Development/Java
java - local host ip address
linuxism
2014. 2. 13. 01:02
In Java, you can use InetAddress.getLocalHost()
to get the Ip Address of the current Server running the Java app.
package com.mkyong; import java.net.InetAddress; import java.net.UnknownHostException; public class Test { public static void main(String[] args) { InetAddress ip; try { ip = InetAddress.getLocalHost(); System.out.println("Current IP address : " + ip.getHostAddress()); } catch (UnknownHostException e) { e.e.printStackTrace(); } } }
Output
Current IP address : 192.168.1.22
출처 - http://www.mkyong.com/java/how-to-get-ip-address-in-java/