def uuid_str_to_bin(uuid):
 matches = re.match('([\\dA-Fa-f]{8})-([\\dA-Fa-f]{4})-([\\dA-Fa-f]{4})-([\\dA-Fa-f]{4})-([\\dA-Fa-f]{4})([\\dA-Fa-f]{8})', uuid)
 (uuid1, uuid2, uuid3, uuid4, uuid5, uuid6) = map((lambda x: long(x, 16)), matches.groups())
 uuid = struct.pack('<LHH', uuid1, uuid2, uuid3)
 uuid += struct.pack('>HHL', uuid4, uuid5, uuid6)
 return uuid

def uuid_str_to_bin ( uuid ) : matches = re . match ( '([\\dA-Fa-f]{8})-([\\dA-Fa-f]{4})-([\\dA-Fa-f]{4})-([\\dA-Fa-f]{4})-([\\dA-Fa-f]{4})([\\dA-Fa-f]{8})' , uuid ) ( uuid1 , uuid2 , uuid3 , uuid4 , uuid5 , uuid6 ) = map ( ( lambda x : long ( x , 16 ) ) , matches . groups ( ) ) uuid = struct . pack ( '<LHH' , uuid1 , uuid2 , uuid3 ) uuid += struct . pack ( '>HHL' , uuid4 , uuid5 , uuid6 ) return uuid
ripped from core impacket .