Example usage for java.net NetworkInterface getClass

List of usage examples for java.net NetworkInterface getClass

Introduction

In this page you can find the example usage for java.net NetworkInterface getClass.

Prototype

@HotSpotIntrinsicCandidate
public final native Class<?> getClass();

Source Link

Document

Returns the runtime class of this Object .

Usage

From source file:org.nuxeo.ecm.core.management.statuses.NuxeoInstanceIdentifierHelper.java

public static String generateHardwareUID() throws Exception {
    String hwUID = "";

    String javaVersion = System.getProperty("java.version");

    Enumeration<NetworkInterface> ifs = NetworkInterface.getNetworkInterfaces();

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

        if (javaVersion.contains("1.6")) {
            // ni.getHardwareAddress() only in jdk 1.6
            Method[] methods = ni.getClass().getMethods();
            for (Method method : methods) {
                if (method.getName().equalsIgnoreCase("getHardwareAddress")) {
                    byte[] hwAddr = (byte[]) method.invoke(ni);
                    if (hwAddr != null) {
                        hwUID = hwUID + "-" + Base64.encodeBytes(hwAddr);
                    }//w w w.ja  va2 s.  c  o  m
                    break;
                }
            }
        } else {
            Enumeration<InetAddress> addrs = ni.getInetAddresses();
            while (addrs.hasMoreElements()) {
                hwUID = hwUID + "-" + Base64.encodeBytes(addrs.nextElement().getAddress());
            }
        }
    }
    return hwUID;
}