Java Network Interface Get getAllInterfaces()

Here you can find the source of getAllInterfaces()

Description

Get all interfaces, including virtual interfaces.

License

Apache License

Exception

Parameter Description
SocketException an exception

Return

A list of all interfaces

Declaration

private static List<NetworkInterface> getAllInterfaces() throws SocketException 

Method Source Code

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

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

import java.util.Collections;

import java.util.List;

import java.util.stream.Collectors;

public class Main {
    /**/* w  w w .j  av a  2s  .com*/
     * Get all interfaces, including virtual interfaces.
     * @return A list of all interfaces
     * @throws SocketException
     */
    private static List<NetworkInterface> getAllInterfaces() throws SocketException {
        List<NetworkInterface> allInterfaces = Collections.list(NetworkInterface.getNetworkInterfaces()).stream()
                .flatMap(m -> {
                    List<NetworkInterface> l = Collections.list(m.getSubInterfaces());
                    l.add(m);
                    return l.stream();
                }).collect(Collectors.toList());
        return allInterfaces;
    }
}

Related

  1. enumerateInterfaces()
  2. getAllAvailableInterfaces()
  3. getAllAvailableInterfaces()
  4. getAllAvailableInterfaces()
  5. getAllInterfaces()
  6. getAllLocalInterfaces()
  7. getAllLocalUsingNetworkInterface()
  8. getAvailableNetworkInterface()