Class MachineId


  • public final class MachineId
    extends Object
    Utility class to generate machine ID. It works in three steps: 1. Create a string containing host name, MAC and IP; 2. Create a hash of the string using SHA-256 algorithm; 3. Create the identifier using part of the resulting hash. If the host name, MAC or IP changes, the identifier will also change.
    • Method Detail

      • getMachineId

        public static long getMachineId()
        Returns a number generated from the machine hash. It uses the first 8 bytes of the machine hash.
        Returns:
        a number
      • getMachineUuid

        public static UUID getMachineUuid()
        Returns a UUID generated from the machine hash. It uses the first 16 bytes of the machine hash. The UUID version is 4.
        Returns:
        a UUID
      • getMachineHexa

        public static String getMachineHexa()
        Returns the machine hash in hexadecimal format. The returning string has 64 chars.
        Returns:
        a string
      • getMachineHash

        public static byte[] getMachineHash()
        Returns the machine hash in a byte array.
        Returns:
        a byte array
      • getMachineString

        public static String getMachineString()
        Returns a string containing host name, MAC and IP. Output format: "hostname123 11-22-33-44-55-66 123.123.123.123" Note: a network interface may have more than one IP address.
        Returns:
        a string