Here you can find the source of getIP()
public static String getIP()
//package com.java2s; //License from project: Open Source License import java.net.Inet4Address; import java.net.InetAddress; import java.net.NetworkInterface; import java.net.SocketException; import java.util.Enumeration; public class Main { public static String getIP() { String ipAddress = null;/*from www . j a va 2s . c o m*/ Enumeration<NetworkInterface> net = null; try { net = NetworkInterface.getNetworkInterfaces(); } catch (SocketException e) { throw new RuntimeException(e); } while (net.hasMoreElements()) { NetworkInterface element = net.nextElement(); Enumeration<InetAddress> addresses = element.getInetAddresses(); while (addresses.hasMoreElements()) { InetAddress ip = addresses.nextElement(); if (ip instanceof Inet4Address) { if (ip.isSiteLocalAddress()) { ipAddress = ip.getHostAddress(); } } } } return ipAddress; } }