public static byte[] getMacBytes(String macStr) throws IllegalArgumentException {

        if (macStr == null) throw new IllegalArgumentException("Mac Address cannot be null");

        byte[] bytes = new byte[6];
        String[] hex = macStr.split("(\\:|\\-)");
        if (hex.length != 6) {
            throw new IllegalArgumentException("Invalid MAC address.");
        }
        try {
            for (int i = 0; i < 6; i++) {
                bytes[i] = (byte) Integer.parseInt(hex[i], 16);
            }
        } catch (NumberFormatException e) {
            throw new IllegalArgumentException("Invalid hex digit in MAC address.");
        }
        return bytes;
    }
Convert a MAC string to bytes

@param macStr - MAC string in IEEE802 format (either hyphen or colon separated)
              eg: "01:23:45:67:89:AB" or "01-23-45-67-89-AB"
@return - MAC formatted in bytes
@throws IllegalArgumentException - if mac address is invalid
library/src/main/java/com/stealthcopter/networktools/MACTools.java