Here you can find the source of getLocalHostIp()
public static String getLocalHostIp()
//package com.java2s; //License from project: Apache License import java.net.InetAddress; import java.net.UnknownHostException; public class Main { public static String getLocalHostIp() { String ip = ""; InetAddress inetAddress;//w w w . j av a2 s. c om try { inetAddress = InetAddress.getByName("localhost"); ip = inetAddress.getHostAddress(); } catch (UnknownHostException e) { throw new RuntimeException("Is your network broken; localhost does not exist?", e); } return ip; } }