ldapsearch example in python-ldap?
Michael Ströder
michael at stroeder.com
Thu Nov 23 11:11:03 EST 2006
Nico Grubert wrote:
>
> on a linux machine I am running this ldapsearch from the command line:
>
> ldapsearch -x -h myldaphost.mydomain.com \
> -D "CN=ldapuser,CN=Users,DC=mydomain,DC=com" -w "secret" \
> -b "CN=ANYCOMPUTER,CN=Computers,DC=mydomain,DC=com"
>
> How can I do this with python-ldap?
http://python-ldap.sourceforge.net/docs.shtml contains some links to
introductions.
This command above boils down to:
l=ldap.initialize("ldap://myldaphost.mydomain.com")
l.simple_bind_s("CN=ldapuser,CN=Users,DC=mydomain,DC=com","secret")
r = l.search_s(
"CN=ANYCOMPUTER,CN=Computers,DC=mydomain,DC=com",
ldap.SCOPE_SUBTREE, # this is the default of ldapsearch
"(objectClass=*)"
)
But you really should learn more about it by diving into:
http://python-ldap.sourceforge.net/doc/python-ldap/ldap-objects.html
Ciao, Michael.
More information about the Python-list
mailing list