Here you can find the source of getLocalHosts()
public static List<String> getLocalHosts()
//package com.java2s; //License from project: Apache License import java.net.InetAddress; import java.net.NetworkInterface; import java.util.ArrayList; import java.util.Enumeration; import java.util.List; public class Main { /**//from w w w. jav a 2 s. c o m * Get host IP address * * @return IP Address */ public static List<String> getLocalHosts() { List<String> list = new ArrayList<>(); try { Enumeration<NetworkInterface> nets = NetworkInterface.getNetworkInterfaces(); while (nets.hasMoreElements()) { NetworkInterface ni = (NetworkInterface) nets.nextElement(); Enumeration<InetAddress> itor = ni.getInetAddresses(); while (itor.hasMoreElements()) { InetAddress inetAddress = itor.nextElement(); String host = inetAddress.getHostName(); list.add(host); } } } catch (Exception e) { throw new IllegalStateException(e); } return list; } }