Here you can find the source of getIPAdresses()
public static InetAddress[] getIPAdresses() throws SocketException
//package com.java2s; //License from project: Open Source License import java.net.InetAddress; import java.net.NetworkInterface; import java.net.SocketException; import java.util.ArrayList; import java.util.Enumeration; import java.util.List; public class Main { public static InetAddress PUBLIC_IP; public static InetAddress[] getIPAdresses() throws SocketException { List<InetAddress> addrList = new ArrayList<InetAddress>(); for (Enumeration<NetworkInterface> nics = NetworkInterface.getNetworkInterfaces(); nics .hasMoreElements();) {/* w ww. java 2 s.com*/ NetworkInterface nic = nics.nextElement(); if (nic.isUp()) { for (Enumeration<InetAddress> addresses = nic.getInetAddresses(); addresses.hasMoreElements();) { InetAddress address = addresses.nextElement(); addrList.add(address); } } } addrList.add(PUBLIC_IP); return addrList.toArray(new InetAddress[0]); } }