code: def mac_str_to_bytes(mac_str):
      '''
      Convert a MAC address string into bytes. Works with or without separators:
  
      b1 = mac_str_to_bytes('08:00:27:13:69:77')
      b2 = mac_str_to_bytes('080027136977')
      assert b1 == b2
      assert isinstance(b1, bytes)
      '''
      if len(mac_str) == 12:
          pass
      elif len(mac_str) == 17:
          sep = mac_str[2]
          mac_str = mac_str.replace(sep, '')
      else:
          raise ValueError('Invalid MAC address')
      chars = (int(mac_str[s:s+2], 16) for s in range(0, 12, 2))
      return bytes(chars) if six.PY3 else b''.join(chr(x) for x in charsf mac_str_to_bytes(mac_str):
      '''
      Convert a MAC address string into bytes. Works with or without separators:
  
      b1 = mac_str_to_bytes('08:00:27:13:69:77')
      b2 = mac_str_to_bytes('080027136977')
      assert b1 == b2
      assert isinstance(b1, bytes)
      '''
      if len(mac_str) == 12:
          pass
      elif len(mac_str) == 17:
          sep = mac_str[2]
          mac_str = mac_str.replace(sep, '')
      else:
          raise ValueError('Invalid MAC address')
      chars = (int(mac_str[s:s+2], 16) for s in range(0, 12, 2))
      return bytes(chars) if six.PY3 else b''.join(chr(x) for x in chars)
docs: Convert a MAC address string into bytes. Works with or without separators:
  
      b1 = mac_str_to_bytes('08:00:27:13:69:77')
      b2 = mac_str_to_bytes('080027136977')
      assert b1 == b2
      assert isinstance(b1, bytes)