要获取所有dn,您可以使用LDAP3库的search功能。以下是示例代码:

from ldap3 import Server, Connection, ALL

# 连接到LDAP服务器
server = Server('ldap://your_server', get_info=ALL)
conn = Connection(server, 'your_dn', 'your_password', auto_bind=True)

# 搜索所有dn
conn.search(search_base='dc=example,dc=com', search_filter='(objectclass=*)', search_scope='BASE')
result = conn.entries

# 打印所有dn
for entry in result:
    print(entry.entry_dn)

在上面的代码中,search_filter='(objectclass=*)'意味着搜索所有对象,search_scope='BASE'意味着只搜索基本对象,而不是搜索整个子树。如果您想搜索整个子树,可以将search_scope设置为SUBTREE

python使用ldap3获取所有dn

原文地址: https://www.cveoy.top/t/topic/qSz 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录