Here you can find the source of getIpAddress()
public static String getIpAddress()
//package com.java2s; //License from project: Apache License import java.net.Inet4Address; import java.net.InetAddress; import java.net.NetworkInterface; import java.util.Enumeration; public class Main { public static String getIpAddress() { String rtip = "unknown.host"; try {/* www .j av a 2 s . c o m*/ Enumeration<NetworkInterface> allNetInterfaces = NetworkInterface.getNetworkInterfaces(); InetAddress ip = null; while (allNetInterfaces.hasMoreElements()) { NetworkInterface netInterface = (NetworkInterface) allNetInterfaces.nextElement(); if (netInterface.isLoopback() || netInterface.isVirtual() || !netInterface.isUp()) { continue; } else { Enumeration<InetAddress> addresses = netInterface.getInetAddresses(); while (addresses.hasMoreElements()) { ip = addresses.nextElement(); if (ip != null && ip instanceof Inet4Address) { rtip = ip.getHostAddress(); } } } } } catch (Exception e) { } return rtip; } }