Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python LDAP converting objectGUID to hex string and back

How do I convert binary ldap attributes returned by python-ldap to a nice hex representation and back again for use in an ldap filter?

like image 959
Rel Avatar asked Feb 07 '26 17:02

Rel


1 Answers

For the task of converting to and from hex string, you should consider the builtin uuid module.

import uuid


object_guid = 'Igr\xafb\x19ME\xb2P9c\xfb\xa0\xe2w'
guid = uuid.UUID(bytes=object_guid)

# to hex
assert guid.hex == '496772af62194d45b2503963fba0e277'

# to human-readable guid
assert str(guid) == '496772af-6219-4d45-b250-3963fba0e277'

# to bytes
assert guid.bytes == object_guid == 'Igr\xafb\x19ME\xb2P9c\xfb\xa0\xe2w'
like image 72
Scotro Avatar answered Feb 09 '26 10:02

Scotro



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!