Java Network Interface Get getAllInterfaces()

Here you can find the source of getAllInterfaces()

Description

Get all the host interfaces including the loopback one

License

Open Source License

Declaration

public static Set<NetworkInterface> getAllInterfaces() 

Method Source Code

//package com.java2s;
/**//w w w. j  a  va2 s.  c o m
 * PETALS - PETALS Services Platform. Copyright (c) 2008 EBM Websourcing,
 * http://www.ebmwebsourcing.com/
 * 
 * This library is free software; you can redistribute it and/or modify it under
 * the terms of the GNU Lesser General Public License as published by the Free
 * Software Foundation; either version 2.1 of the License, or (at your option)
 * any later version. This library is distributed in the hope that it will be
 * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
 * General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public License
 * along with this library; if not, write to the Free Software Foundation, Inc.,
 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 * 
 * -------------------------------------------------------------------------
 * $Id$
 * -------------------------------------------------------------------------
 */

import java.net.NetworkInterface;
import java.net.SocketException;
import java.util.Enumeration;
import java.util.HashSet;
import java.util.Set;

public class Main {
    /**
     * Get all the host interfaces including the loopback one
     * 
     * @return
     */
    public static Set<NetworkInterface> getAllInterfaces() {
        Set<NetworkInterface> result = new HashSet<NetworkInterface>();
        try {
            Enumeration<NetworkInterface> e = NetworkInterface.getNetworkInterfaces();
            while (e.hasMoreElements()) {
                result.add(e.nextElement());
            }
        } catch (SocketException e) {
        }
        return result;
    }
}

Related

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