/** * Returns the Ethernet-Address of the locale host.<p> * * A dummy ethernet address is returned, if the ip is * representing the loopback address or in case of exceptions.<p> * * @return the Ethernet-Address */ public static String getEthernetAddress() { try { InetAddress ip = InetAddress.getLocalHost(); if (!ip.isLoopbackAddress()) { NetworkInterface network = NetworkInterface.getByInetAddress(ip); byte[] mac = network.getHardwareAddress(); StringBuilder sb = new StringBuilder(); for (int i = 0; i < mac.length; i++) { sb.append(String.format("%02X%s", new Byte(mac[i]), (i < (mac.length - 1)) ? ":" : "")); } return sb.toString(); } } catch (Throwable t) { // if an exception occurred return a dummy address } // return a dummy ethernet address, if the ip is representing the loopback address or in case of exceptions return CmsUUID.getDummyEthernetAddress(); }
/** * Creates a new UUID.<p> * * Please note that the static init() method has to be called first to initialize the * internet address of the machine.<p> */ public CmsUUID() { if (m_ethernetAddress == null) { // if no ethernet address is available, generate a dummy // this is required because otherwise we can't ever de-serialize a CmsUUID outside of OpenCms, // since the empty constructor is called when the de-serialization takes place init(getDummyEthernetAddress()); } m_uuid = UUIDGenerator.getInstance().generateTimeBasedUUID(m_ethernetAddress); }
String ethernetAddress = configuration.getString("server.ethernet.address", CmsUUID.getDummyEthernetAddress()); if (CmsLog.INIT.isInfoEnabled()) { CmsLog.INIT.info(Messages.get().getBundle().key(Messages.INIT_ETHERNET_ADDRESS_1, ethernetAddress));