def mac_str_to_bytes(mac_str):
 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')
 if six.PY3:
  mac_bytes = bytes((int(mac_str[s:(s + 2)], 16) for s in range(0, 12, 2)))
 else:
  mac_bytes = ''.join((chr(int(mac_str[s:(s + 2)], 16)) for s in range(0, 12, 2)))
 return mac_bytes

def mac_str_to_bytes ( mac_str ) : 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' ) if six . PY3 : mac_bytes = bytes ( ( int ( mac_str [ s : ( s + 2 ) ] , 16 ) for s in range ( 0 , 12 , 2 ) ) ) else : mac_bytes = '' . join ( ( chr ( int ( mac_str [ s : ( s + 2 ) ] , 16 ) ) for s in range ( 0 , 12 , 2 ) ) ) return mac_bytes
convert a mac address string into bytes .