ldapsearch example in python-ldap?

N

Nico Grubert

Hi there,

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?

Regards,
Nico
 
?

=?ISO-8859-1?Q?Michael_Str=F6der?=

Nico said:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top