Java Network Interface Get getInterfaces()

Here you can find the source of getInterfaces()

Description

get Interfaces

License

Creative Commons License

Declaration

public static List<InterfaceAddress> getInterfaces() 

Method Source Code


//package com.java2s;
//License from project: Creative Commons License 

import java.net.InterfaceAddress;
import java.net.NetworkInterface;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.List;

public class Main {
    public static List<InterfaceAddress> getInterfaces() {
        List<InterfaceAddress> result = new ArrayList<InterfaceAddress>();

        try {/*from  w w  w . ja  va2s . com*/
            Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces();

            while (en.hasMoreElements()) {
                NetworkInterface ni = (NetworkInterface) en.nextElement();

                for (InterfaceAddress address : ni.getInterfaceAddresses()) {
                    if (!address.getAddress().getHostAddress().contains(":")
                            && !address.getAddress().getHostAddress().contains("127.0.0.1"))
                        result.add(address);
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

        return result;
    }
}

Related

  1. getHostnameFromNetworkInterface()
  2. getInterface(String ifaceName)
  3. getInterfaceByName(String interfaceName)
  4. getInterfaceDiagnostic()
  5. getInterfaceInfo(NetworkInterface nif)
  6. getInterfaces()
  7. getInterfaces()
  8. getInterfaces()
  9. getInterfaces()