【问题标题】:How to retrieve all OU of Active Directory in LDAP?如何在 LDAP 中检索 Active Directory 的所有 OU?
【发布时间】:2016-06-15 06:37:37
【问题描述】:

我正在使用 ldap3。我想检索 AD 的所有组织单位。 这是我的代码

from ldap3 import Server, Connection, SUBTREE, ALL
total_entries = 0

s = Server('172.30.1.197', port=636, use_ssl=True, get_info=ALL)
admin_username = "Administrator@naanal.local"
admin_password = "p@ssw0rd1"
c = Connection(s, user=admin_username, password=admin_password)
c.bind()
c.start_tls()

c.search(search_base = 'dc=naanal,dc=local',
         search_filter = '(objectClass=OrganizationalUnit)',
         search_scope = SUBTREE,
         paged_size = 5)

total_entries += len(c.response)

for entry in c.response:
    print(entry)

print('Total entries retrieved:', total_entries)

输出:

{'dn': u'OU=Domain Controllers,DC=naanal,DC=local', 'attributes': {}, 'raw_attributes': {}, 'type': 'searchResEntry'}
{'dn': u'OU=Police,DC=naanal,DC=local', 'attributes': {}, 'raw_attributes': {}, 'type': 'searchResEntry'}
{'dn': u'OU=dummy,DC=naanal,DC=local', 'attributes': {}, 'raw_attributes': {}, 'type': 'searchResEntry'}
{'type': 'searchResRef', 'uri': ['ldaps://ForestDnsZones.naanal.local/DC=ForestDnsZones,DC=naanal,DC=local']}
{'type': 'searchResRef', 'uri': ['ldaps://DomainDnsZones.naanal.local/DC=DomainDnsZones,DC=naanal,DC=local']}
{'type': 'searchResRef', 'uri': ['ldaps://naanal.local/CN=Configuration,DC=naanal,DC=local']}
('Total entries retrieved:', 6)

结果中的最后三个条目是什么?为什么会来?

【问题讨论】:

    标签: python active-directory ldap


    【解决方案1】:

    最后三个条目看起来像推荐。根据文档,可以禁用推荐追逐。见这里:http://ldap3.readthedocs.io/connections.html

    c = Connection(s, user=admin_username, password=admin_password, auto_referrals=False)
    

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-09-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-23
    相关资源
    最近更新 更多