Skip to content

Instantly share code, notes, and snippets.

@asafge
Last active December 27, 2015 16:19
Show Gist options
  • Save asafge/7354124 to your computer and use it in GitHub Desktop.
Save asafge/7354124 to your computer and use it in GitHub Desktop.
ldap - bind and query a directory with python-ldap
import ldap
# Initialize and bind
con = ldap.initialize('ldap://10.0.0.23')
dn = "cn=test,dc=example,dc=com"
pw = "Pass1"
con.simple_bind_s(dn, pw)
# Run a query against the directory
baseDN = "cn=users,dc=example,dc=com"
searchScope = ldap.SCOPE_SUBTREE
retrieveAttributes = None
searchFilter = "cn=*asaf*"
res = con.search_s(baseDN, searchScope, searchFilter, retrieveAttributes)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment