Here you can find the source of getIpAddress()
public static String getIpAddress()
//package com.java2s; //License from project: Open Source License import java.net.InetAddress; import java.net.NetworkInterface; import java.util.Enumeration; public class Main { public static String getIpAddress() { String hostaddress = "localhost"; try {/*from w w w . j a va 2 s. co m*/ Enumeration<NetworkInterface> e = NetworkInterface.getNetworkInterfaces(); while (e.hasMoreElements()) { NetworkInterface n = e.nextElement(); Enumeration<InetAddress> ee = n.getInetAddresses(); while (ee.hasMoreElements()) { InetAddress i = ee.nextElement(); String[] ha = i.getHostAddress().split("\\."); if (ha.length == 4 && !ha[0].equals("127")) { hostaddress = i.getHostAddress(); } } } } catch (Exception ex) { // TODO: handle exception } return hostaddress; } }