Class MACNumber


  • public final class MACNumber
    extends Object
    A MACNumber is the unique number associated to a network interface.
    Since:
    4.2
    Version:
    17.0 2020-01-04 14:41:35
    Author:
    Stéphane GALLAND
    See Also:
    NetworkInterface
    Maven Group Id:
    org.arakhne.afc.core
    Maven Artifact Id:
    vmutils
    • Field Detail

      • MACNUMBER_SEPARATOR

        public static final char MACNUMBER_SEPARATOR
        Character that is used as separator inside MAC addresses.
        See Also:
        Constant Field Values
      • NULL

        public static final MACNumber NULL
        Constant ethernet address object which has the "null address".

        This constant can be used when you want a non-null MACAddress object reference, but want a invalid (or null) MAC address contained.

        See Also:
        isNull()
    • Constructor Detail

      • MACNumber

        public MACNumber()
        Constructs object with "null values" (address of "0:0:0:0:0:0").
      • MACNumber

        public MACNumber​(byte[] bytes)
        Build a MACNumber from a set of bytes. The byte array must contains 6 elements.
        Parameters:
        bytes - is the list of bytes from which the address must be built.
        Throws:
        IllegalArgumentException - if the byte array does not corresponds to a valid MAC Number.
      • MACNumber

        public MACNumber​(String address)
        Build a MACNumber from a string representation.
        Parameters:
        address - is the string representation of a MAC address
        Throws:
        IllegalArgumentException - if the byte array does not corresponds to a valid MAC Number.
        See Also:
        toString()
    • Method Detail

      • parse

        @Pure
        public static MACNumber[] parse​(String addresses)
        Parse the specified string an repleis the corresponding MAC numbers.
        Parameters:
        addresses - is the string to parse
        Returns:
        a list of addresses.
        Throws:
        IllegalArgumentException - is the argument has not the right syntax.
      • parseAsString

        @Pure
        public static String[] parseAsString​(String addresses)
        Parse the specified string an repleis the corresponding MAC numbers.
        Parameters:
        addresses - is the string to parse
        Returns:
        a list of addresses.
        Throws:
        IllegalArgumentException - is the argument has not the right syntax.
      • join

        @Pure
        public static String join​(MACNumber... addresses)
        Join the specified MAC numbers to reply a string.
        Parameters:
        addresses - is the list of mac addresses to join.
        Returns:
        the joined string.
      • getAllAdapters

        @Pure
        public static Collection<MACNumber> getAllAdapters()
        Get all of the ethernet addresses associated with the local machine.

        This method will try and find ALL of the ethernet adapters which are currently available on the system. This is heavily OS dependent and may not be supported on all platforms. When not supported, you should still get back a collection with the primary adapter in it.

        Returns:
        the list of MAC numbers associated to the physical devices.
        See Also:
        getPrimaryAdapter()
      • getAllMappings

        @Pure
        public static Map<InetAddress,​MACNumber> getAllMappings()
        Get all of the internet address and ethernet address mappings on the local machine.

        This method will try and find ALL of the ethernet adapters which are currently available on the system. This is heavily OS dependent and may not be supported on all platforms. When not supported, you should still get back a collection with the primary adapter in it.

        Returns:
        the map internet address and ethernet address mapping.
        See Also:
        getPrimaryAdapterAddresses()
      • getPrimaryAdapter

        @Pure
        public static MACNumber getPrimaryAdapter()
        Try to determine the primary ethernet address of the machine.
        Returns:
        the primary MACNumber or null
      • getPrimaryAdapterAddresses

        @Pure
        public static Collection<InetAddress> getPrimaryAdapterAddresses()
        Try to determine the primary ethernet address of the machine and replies the associated internet addresses.
        Returns:
        the internet addresses of the primary network interface.
      • equals

        @Pure
        public boolean equals​(Object object)
        Overrides:
        equals in class Object
      • hashCode

        @Pure
        public int hashCode()
        Overrides:
        hashCode in class Object
      • isNull

        @Pure
        public boolean isNull()
        Replies if all the MAC address number are equal to zero.
        Returns:
        true if all the bytes are zero.
        See Also:
        NULL
      • getBytes

        @Pure
        public byte[] getBytes()
        Replies the bytes that compose this MAC Address.
        Returns:
        a copy of the current bytes.