4
# import class and constants
from ldap3 import Server, Connection, ALL, SUBTREE

# define the server
s = Server(host='xyz', port=xxxx, use_ssl=True, get_info='ALL')
c = Connection(s, auto_bind='NONE', version=3, authentication='ANONYMOUS', client_strategy='SYNC', auto_referrals=True, check_names=True, read_only=False, lazy=False, raise_exceptions=False)

c.bind()
results = c.extend.standard.paged_search(
    search_base = 'Ou=XYZ,dc=org,dc=com',
    search_filter = '(AppID=*)',
    search_scope = SUBTREE,
    get_operational_attributes=True,
    attributes=['*'],
    generator=True,
    paged_size=None
)
i=0

for entries in results:
    print(entries)
    i+=1
print(i)

I am trying to connect to a server on a specific port and doing an ANONYMOUS SSL authentication. I have written the above script to get the results for "AppID=*". I am only able to print 1000 records and after that I run into the following error:

Traceback (most recent call last): File "C:/Fetch data.py", line 43, in for entries in results: File "C:\Users\xyz\AppData\Local\Programs\Python\Python36\lib\site-packages\ldap3\extend\standard\PagedSearch.py", line 75, in paged_search_generator raise LDAPOperationResult(result=result['result'], description=result['description'], dn=result['dn'], message=result['message'], response_type=result['type']) ldap3.core.exceptions.LDAPSizeLimitExceededResult: LDAPSizeLimitExceededResult - 4 - sizeLimitExceeded - None - None - searchResDone - None

I have tried the solutions provided Conquering Active Directory's 1000 record limit

I have tried going through the document LDAP3 Docs but no success. Is there a way to read complete output. (I imagine there are more than 5k records)

Jack
  • 300
  • 2
  • 9

1 Answers1

3

The problem here is that your code would generate a generator object.

from ldap3 import Server, Connection, SUBTREE
import ldap3
total_entries = 0
# define the server
s = Server(host='xyz', port=xxxx, use_ssl=True, get_info=ldap3.NONE)
c = Connection(s,authentication='ANONYMOUS') 
# subtitute your filter here 
filter = '(&(objectClass=group)(sAMAccountName=))'
entry_generator = c.extend.standard.paged_search(search_base = 'Ou=XYZ,dc=org,dc=com',
                                                 search_filter = filter,
                                                 search_scope = SUBTREE,
                                                 get_operational_attributes=True,
                                                 attributes = ['*'],
                                                 paged_size = 1000,
                                                 generator=True)
for entry in entry_generator:
    total_entries += 1
    print(entry['dn'], entry['attributes'])
print('Total entries retrieved:', total_entries) 

This should give you all the details that you need. Reference ldap3 documents.

Steve_Greenwood
  • 546
  • 8
  • 20
  • I tried something similar that worked . You have answered my question. Thank you! :D – Jack Mar 08 '20 at 21:13