I am using the python ldap module to connect to the ldap server. I am able to query the database, but I donโt know how to get the fields present in the database, so that I can notify the user in advance by requesting the database, telling him that the field that he is trying to access is not in the database.
A simple solution would be to search and then print a list of keys from the result.
import ldap # connect to your ldap server some_dn = '...' # Your base dn some_lookup = '...' # your lookup attr result = conn.search_s(some_dn,ldap.SCOPE_SUBTREE,some_lookup) result[0][1].keys()
For example, against my AD server, it returns the following:
['mailNickname', 'publicDelegatesBL', 'logonCount', 'cn', 'countryCode', 'dSCorePropagationData', 'objectClass', # ... many many more 'telephoneNumber', 'physicalDeliveryOfficeName', 'name', 'memberOf', 'codePage', 'userAccountControl', 'msExchMDBRulesQuota', 'lastLogon', 'protocolSettings', 'uSNChanged', 'sn', 'msExchVersion', 'mDBUseDefaults', 'givenName', 'msExchMailboxGuid', 'lastLogoff']