Here you can find the source of getLocalHostIps()
public static String getLocalHostIps()
//package com.java2s; /*//from www .j a va 2s. c o m * BJAF - Beetle J2EE Application Framework * ???J2EE??????????? * ??????2003-2015 ??? (www.beetlesoft.net) * * ?????????????????? *<http://www.apache.org/licenses/LICENSE-2.0> *???????????????????????? * * ??????????????????????????????? * ??? <yuhaodong@gmail.com/>. */ import java.net.InetAddress; import java.net.NetworkInterface; import java.util.Enumeration; public class Main { public static String getLocalHostIps() { StringBuffer sb = new StringBuffer(); final char flag = 2; try { Enumeration<?> netInterfaces = NetworkInterface.getNetworkInterfaces(); while (netInterfaces.hasMoreElements()) { NetworkInterface ni = (NetworkInterface) netInterfaces.nextElement(); Enumeration<InetAddress> ips = ni.getInetAddresses(); while (ips.hasMoreElements()) { InetAddress inetAddress = ips.nextElement(); String ip = inetAddress.getHostAddress(); if (!inetAddress.isLoopbackAddress() && ip.indexOf(":") == -1) { sb.append(ip).append(flag); } } } } catch (Exception e) { return ""; } return sb.toString(); } }