Last active
November 9, 2020 20:58
-
-
Save AbirRazzak/fd1ef73e6e639a542c7012d22fd33a19 to your computer and use it in GitHub Desktop.
Demo python-ldap script for senior design
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import ldap | |
print('Connecting to ldap server...') | |
connect = ldap.initialize('ldap://localhost') | |
connect.set_option(ldap.OPT_REFERRALS, 0) | |
connect.simple_bind_s('cn=admin,dc=example,dc=com', 'redhat') | |
print('Connected!\n') | |
print('\nSearch for user with uid = amr439') | |
result = connect.search_s('dc=example,dc=com', ldap.SCOPE_SUBTREE, '(uid=amr439)') | |
for r in result: | |
print(r) | |
print('\nSearch for all user groups') | |
result = connect.search_s('dc=example,dc=com', ldap.SCOPE_SUBTREE, '(objectclass=groupOfNames)', ['cn']) | |
for r in result: | |
print(r) | |
print('\nSearch for all members in the "doctors" groups') | |
result = connect.search_s('dc=example,dc=com', ldap.SCOPE_SUBTREE, '(cn=doctors)', ['member']) | |
for r in result: | |
print(r) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Installation: