Here you can find the source of getHostAddresses()
@SuppressWarnings("rawtypes") public final static List<String> getHostAddresses() throws Throwable
//package com.java2s; //License from project: Apache License import java.net.Inet6Address; import java.net.InetAddress; import java.net.NetworkInterface; import java.util.ArrayList; import java.util.Enumeration; import java.util.List; public class Main { @SuppressWarnings("rawtypes") public final static List<String> getHostAddresses() throws Throwable { List<String> result = new ArrayList<>(); Enumeration e = NetworkInterface.getNetworkInterfaces(); while (e.hasMoreElements()) { NetworkInterface n = (NetworkInterface) e.nextElement(); Enumeration ee = n.getInetAddresses(); while (ee.hasMoreElements()) { InetAddress i = (InetAddress) ee.nextElement(); //System.out.println(i.getHostAddress()); if (i instanceof Inet6Address || i .isLoopbackAddress()/*.getHostAddress().contains("127.0.0.1") || i.getHostAddress().contains("0:0:0:0:0")*/) continue; result.add(i.getHostAddress()); }//from w w w . j a va 2s . c o m } return result; } }