Created
June 3, 2021 23:55
-
-
Save deeso/ca020d78154a1fc9edf3d24b888d7285 to your computer and use it in GitHub Desktop.
Searching Ldap with ldap3
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 ldap3 | |
password = '' | |
host_ip = "" | |
user_dn = "cn=Allen,OU=abc,OU=efgh,OU=zyx,DC=fqdg,DC=internal" | |
USERNAME = 'username' | |
DISPLAY_NAME = 'displayName' | |
MANAGER = 'manager' | |
NAME = 'name' | |
MAIL = 'mail' | |
TITLE = 'title' | |
MEMBER_OF = 'memberOf' | |
SUBJECT_ATTRIBUTES = [DISPLAY_NAME, TITLE, NAME, MAIL, MANAGER, MEMBER_OF] | |
server = ldap3.Server(host_ip, get_info=ldap3.ALL) | |
conn = ldap3.Connection(server,user_dn, password, auto_bind=True) | |
conn.bind() | |
ldap_filter = "(cn=*)" | |
base_dn = "OU=abc,OU=efgh,OU=zyx,DC=fqdg,DC=internal" | |
entry_generator = conn.extend.standard.paged_search(base_dn, | |
ldap_filter, | |
search_scope=ldap3.SUBTREE, | |
attributes=SUBJECT_ATTRIBUTES, | |
paged_size=200, | |
generator=True) | |
entries = [e for e in entry_generator] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment