Here you can find the source of getLocalAddress()
public static String getLocalAddress()
//package com.java2s; //License from project: Apache License import java.net.Inet4Address; import java.net.InetAddress; import java.net.NetworkInterface; import java.net.SocketException; import java.util.Enumeration; public class Main { /**/*from ww w . j a va 2 s . com*/ * Gets the local address. * * @return the local address */ public static String getLocalAddress() { Enumeration<NetworkInterface> allNetInterfaces; try { allNetInterfaces = NetworkInterface.getNetworkInterfaces(); } catch (SocketException e) { // TODO Auto-generated catch block e.printStackTrace(); return "NO"; } InetAddress ip = null; String ips = ""; while (allNetInterfaces.hasMoreElements()) { NetworkInterface netInterface = (NetworkInterface) allNetInterfaces.nextElement(); Enumeration addresses = netInterface.getInetAddresses(); while (addresses.hasMoreElements()) { ip = (InetAddress) addresses.nextElement(); if (ip != null && ip instanceof Inet4Address) { ips += ip.getHostAddress() + " "; } } } return ips; } }