Here you can find the source of getLocalIPAddress()
public static String getLocalIPAddress() throws SocketException
//package com.java2s; //License from project: Open Source License import java.net.InetAddress; import java.net.NetworkInterface; import java.net.SocketException; import java.util.Enumeration; public class Main { public static String getLocalIPAddress() throws SocketException { String ipAddress = null;//from www .j a v a 2 s .c om Enumeration<NetworkInterface> eIf = NetworkInterface.getNetworkInterfaces(); while (ipAddress == null && eIf.hasMoreElements()) { NetworkInterface nIf = eIf.nextElement(); Enumeration<InetAddress> eAddress = nIf.getInetAddresses(); while (eAddress.hasMoreElements()) { InetAddress address = eAddress.nextElement(); if (!address.isLoopbackAddress()) { ipAddress = address.getHostAddress(); } } } return ipAddress; } }