Here you can find the source of getLocalIPAddress()
public static String getLocalIPAddress()
//package com.java2s; /******************************************************************************* * Copyright (c) 2015 LegSem.//from w w w .j av a 2s . co m * All rights reserved. This program and the accompanying materials * are made available under the terms of the GNU Lesser Public License v2.1 * which accompanies this distribution, and is available at * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html * * Contributors: * LegSem - initial API and implementation ******************************************************************************/ import java.net.InetAddress; import java.net.UnknownHostException; public class Main { /** * Retrieve the IP address of the generation machine . * * @return the local machine IP address */ public static String getLocalIPAddress() { try { InetAddress addr = InetAddress.getLocalHost(); byte[] ipAddr = addr.getAddress(); String ipAddrStr = ""; for (int i = 0; i < ipAddr.length; i++) { if (i > 0) { ipAddrStr += "."; } ipAddrStr += ipAddr[i] & 0xFF; } return ipAddrStr; } catch (UnknownHostException e) { return ""; } } }