Here you can find the source of getLocalIP()
public static String getLocalIP()
//package com.java2s; //License from project: Apache License import java.net.InetAddress; import java.net.NetworkInterface; import java.net.SocketException; import java.util.*; public class Main { public static String getLocalIP() { StringBuilder IFCONFIG = new StringBuilder(); try {// w ww . j a v a 2 s . com for (Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces(); en .hasMoreElements();) { NetworkInterface intf = en.nextElement(); for (Enumeration<InetAddress> enumIpAddr = intf.getInetAddresses(); enumIpAddr.hasMoreElements();) { InetAddress inetAddress = enumIpAddr.nextElement(); if (!inetAddress.isLoopbackAddress() && !inetAddress.isLinkLocalAddress() && inetAddress.isSiteLocalAddress()) { IFCONFIG.append(inetAddress.getHostAddress().toString()); } } } } catch (SocketException ex) { } return IFCONFIG.toString(); } }