2016-06-15 6 views
1

私はldap3を使用しています。私はADのすべてのOrganizationalユニットを取得したいと思います。 ここに私のコードLDAPでActive DirectoryのすべてのOUを取得する方法は?

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 = "[email protected]" 
admin_password = "[email protected]" 
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) 

結果の最後の3つのエントリは何ですか?なぜそれが来るのですか?

答えて

0

最後の3つのエントリはリフェラルのように見えます。ドキュメントによると、紹介追跡は無効にすることができます。ここを参照してください:http://ldap3.readthedocs.io/connections.html

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

私が試したが、それでも、私は同じ結果を得る:( – rajagopalx

+1

うーん...これによると、それは避けられないかもしれません。https://mail.python.org/pipermail/python3-ldap /2014/000042.htmlこれはちょっとばかげているようです。検索のための 'dereference_aliases'オプションもあります。これは動作を変更し、' DEREF_NEVER'に設定しようとします。 – ChadSikorra

関連する問題