Java Network Interface Get getInterfaces()

Here you can find the source of getInterfaces()

Description

get Interfaces

License

Apache License

Declaration

public static Map<String, String> getInterfaces() 

Method Source Code

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

import java.net.InetAddress;
import java.net.NetworkInterface;

import java.util.Enumeration;
import java.util.HashMap;
import java.util.Map;

public class Main {
    public static Map<String, String> getInterfaces() {
        Map<String, String> interfaces = new HashMap<String, String>();

        try {/*from www.  ja va2 s. c o m*/
            Enumeration<NetworkInterface> e = NetworkInterface.getNetworkInterfaces();

            while (e.hasMoreElements()) {
                NetworkInterface ni = (NetworkInterface) e.nextElement();
                String nameInterface = ni.getName();

                Enumeration<InetAddress> e2 = ni.getInetAddresses();

                while (e2.hasMoreElements()) {
                    InetAddress ipAddr = (InetAddress) e2.nextElement();
                    if (ipAddr.getHostAddress().contains(".")) {
                        String ip = ipAddr.getHostAddress();
                        interfaces.put(nameInterface, ip);
                    }
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

        return interfaces;
    }
}

Related

  1. getInterfaceInfo(NetworkInterface nif)
  2. getInterfaces()
  3. getInterfaces()
  4. getInterfaces()
  5. getInterfaces()
  6. getInterfaces(final String interfaceName)
  7. getKey()
  8. getLinkLocalScopeId()
  9. getLocalInterfaces()