Here you can find the source of getHostIp()
public static String getHostIp()
//package com.java2s; //License from project: Apache License import java.net.InetAddress; import java.net.UnknownHostException; public class Main { private static InetAddress netAddress = null; public static String getHostIp() { if (null == getInetAddress()) { return null; }/*from w ww . j a v a2 s . c o m*/ String ip = getInetAddress().getHostAddress(); //get the ip address return ip; } public static InetAddress getInetAddress() { if (netAddress == null) { try { netAddress = InetAddress.getLocalHost(); } catch (UnknownHostException e) { System.out.println("unknown host!"); } } return netAddress; } }