Java Network Interface Get getAllAvailableInterfaces()

Here you can find the source of getAllAvailableInterfaces()

Description

Returns all the available interfaces, including first level sub interfaces.

License

Apache License

Declaration

public static List<NetworkInterface> getAllAvailableInterfaces() throws SocketException 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.net.NetworkInterface;
import java.net.SocketException;

import java.util.ArrayList;

import java.util.Enumeration;
import java.util.List;

public class Main {
    /**/*from www .  j  a va 2 s  .c  o m*/
     * Returns all the available interfaces, including first level sub
     * interfaces.
     */
    public static List<NetworkInterface> getAllAvailableInterfaces() throws SocketException {
        List<NetworkInterface> allInterfaces = new ArrayList<>();
        for (Enumeration<NetworkInterface> interfaces = NetworkInterface.getNetworkInterfaces(); interfaces
                .hasMoreElements();) {
            NetworkInterface intf = interfaces.nextElement();
            allInterfaces.add(intf);

            Enumeration<NetworkInterface> subInterfaces = intf.getSubInterfaces();
            if (subInterfaces != null && subInterfaces.hasMoreElements()) {
                while (subInterfaces.hasMoreElements()) {
                    allInterfaces.add(subInterfaces.nextElement());
                }
            }
        }
        return allInterfaces;
    }
}

Related

  1. enumerateInterfaces()
  2. getAllAvailableInterfaces()
  3. getAllAvailableInterfaces()
  4. getAllInterfaces()
  5. getAllInterfaces()