Here you can find the source of getLocalIpAddress()
public static String getLocalIpAddress() throws Exception
//package com.java2s; //License from project: LGPL import java.net.InetAddress; import java.net.NetworkInterface; import java.util.Enumeration; public class Main { public static String getLocalIpAddress() throws Exception { String ipAddress = null;/*from w w w . j a v a 2 s. c o m*/ Enumeration<NetworkInterface> en = NetworkInterface .getNetworkInterfaces(); while (en.hasMoreElements()) { NetworkInterface e = en.nextElement(); Enumeration<InetAddress> addresses = e.getInetAddresses(); while (addresses.hasMoreElements()) { InetAddress address = addresses.nextElement(); if (!address.isLoopbackAddress() && address.isSiteLocalAddress()) { ipAddress = address.getHostName(); break; } } } if (ipAddress == null) { ipAddress = InetAddress.getLocalHost().getHostAddress(); } return ipAddress; } }