Class MacAddressUtil


  • public final class MacAddressUtil
    extends java.lang.Object
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      private MacAddressUtil()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static byte[] bestAvailableMac()
      Obtains the best MAC address found on local network interfaces.
      (package private) static int compareAddresses​(byte[] current, byte[] candidate)  
      private static int compareAddresses​(java.net.InetAddress current, java.net.InetAddress candidate)  
      static byte[] defaultMachineId()
      Returns the result of bestAvailableMac() if non-null otherwise returns a random EUI-64 MAC address.
      static java.lang.String formatAddress​(byte[] addr)  
      static byte[] parseMAC​(java.lang.String value)
      Parse a EUI-48, MAC-48, or EUI-64 MAC address from a String and return it as a byte[].
      private static int scoreAddress​(java.net.InetAddress addr)  
      private static void validateMacSeparator​(char separator)  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • MacAddressUtil

        private MacAddressUtil()
    • Method Detail

      • bestAvailableMac

        public static byte[] bestAvailableMac()
        Obtains the best MAC address found on local network interfaces. Generally speaking, an active network interface used on public networks is better than a local network interface.
        Returns:
        byte array containing a MAC. null if no MAC can be found.
      • defaultMachineId

        public static byte[] defaultMachineId()
        Returns the result of bestAvailableMac() if non-null otherwise returns a random EUI-64 MAC address.
      • parseMAC

        public static byte[] parseMAC​(java.lang.String value)
        Parse a EUI-48, MAC-48, or EUI-64 MAC address from a String and return it as a byte[].
        Parameters:
        value - The string representation of the MAC address.
        Returns:
        The byte representation of the MAC address.
      • validateMacSeparator

        private static void validateMacSeparator​(char separator)
      • formatAddress

        public static java.lang.String formatAddress​(byte[] addr)
        Parameters:
        addr - byte array of a MAC address.
        Returns:
        hex formatted MAC address.
      • compareAddresses

        static int compareAddresses​(byte[] current,
                                    byte[] candidate)
        Returns:
        positive - current is better, 0 - cannot tell from MAC addr, negative - candidate is better.
      • compareAddresses

        private static int compareAddresses​(java.net.InetAddress current,
                                            java.net.InetAddress candidate)
        Returns:
        positive - current is better, 0 - cannot tell, negative - candidate is better
      • scoreAddress

        private static int scoreAddress​(java.net.InetAddress addr)