Here you can find the source of getLocalIP()
public static String getLocalIP() throws SocketException
//package com.java2s; /**// ww w .ja v a 2s . co m * License: https://github.com/votingsystem/votingsystem/wiki/Licencia */ import java.net.InetAddress; import java.net.NetworkInterface; import java.net.SocketException; import java.util.*; public class Main { public static String getLocalIP() throws SocketException { Enumeration<NetworkInterface> nets = NetworkInterface.getNetworkInterfaces(); for (NetworkInterface netint : Collections.list(nets)) { Enumeration<InetAddress> inetAddresses = netint.getInetAddresses(); for (InetAddress inetAddress : Collections.list(inetAddresses)) { if (inetAddress.isSiteLocalAddress()) { String inetAddressStr = inetAddress.toString(); while (inetAddressStr.startsWith("/")) inetAddressStr = inetAddressStr.substring(1); return inetAddressStr; } } } return null; } }