Here you can find the source of getNetworkInterfaces()
private static List<NetworkInterface> getNetworkInterfaces() throws SocketException
//package com.java2s; //License from project: Apache License import java.net.NetworkInterface; import java.net.SocketException; import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; import java.util.Enumeration; import java.util.List; public class Main { private static List<NetworkInterface> getNetworkInterfaces() throws SocketException { List<NetworkInterface> networkInterfaces = new ArrayList<>(); Enumeration<NetworkInterface> interfaces = NetworkInterface.getNetworkInterfaces(); while (interfaces.hasMoreElements()) { NetworkInterface networkInterface = interfaces.nextElement(); networkInterfaces.add(networkInterface); Enumeration<NetworkInterface> subInterfaces = networkInterface.getSubInterfaces(); if (subInterfaces.hasMoreElements()) { while (subInterfaces.hasMoreElements()) { networkInterfaces.add(subInterfaces.nextElement()); }/* w ww . j av a 2s .co m*/ } } sortInterfaces(networkInterfaces); return networkInterfaces; } private static void sortInterfaces(List<NetworkInterface> interfaces) { Collections.sort(interfaces, new Comparator<NetworkInterface>() { @Override public int compare(NetworkInterface o1, NetworkInterface o2) { return Integer.compare(o1.getIndex(), o2.getIndex()); } }); } }