Java Network Interface Get getNetworkInterfaces()

Here you can find the source of getNetworkInterfaces()

Description

Utility method for accessing public interfaces.

License

Apache License

Exception

Parameter Description
SocketException If there's a socket error accessing theinterfaces.

Return

The of public interfaces.

Declaration

public static Collection<InetAddress> getNetworkInterfaces() throws SocketException 

Method Source Code

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

import java.net.InetAddress;

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

import java.util.ArrayList;
import java.util.Collection;
import java.util.Enumeration;

public class Main {
    /**//from  w  w  w  . java 2  s.  co  m
     * Utility method for accessing public interfaces.
     * 
     * @return The {@link Collection} of public interfaces.
     * @throws SocketException If there's a socket error accessing the
     * interfaces.
     */
    public static Collection<InetAddress> getNetworkInterfaces() throws SocketException {
        final Collection<InetAddress> addresses = new ArrayList<InetAddress>();
        final Enumeration<NetworkInterface> e = NetworkInterface.getNetworkInterfaces();
        while (e.hasMoreElements()) {
            final NetworkInterface ni = e.nextElement();
            final Enumeration<InetAddress> niAddresses = ni.getInetAddresses();
            while (niAddresses.hasMoreElements()) {
                addresses.add(niAddresses.nextElement());
            }
        }
        return addresses;
    }
}

Related

  1. getNetworkInterfaceInfo(NetworkInterface pNif)
  2. getNetworkInterfaces( Predicate predicate)
  3. getNetworkInterfaces()
  4. getNetworkInterfaces()
  5. getNetworkInterfaces()
  6. getNetworkInterfaces()
  7. getNetworkInterfaces()
  8. getNetworkInterfaces()
  9. getNIOMulticastMethod()