I have the below script to extract data from ldap. Python version is 2.7. However I am not able to write the contents to a csv file. Any help is appreciated.
import csv
import ldap
host = ‘ldap://test.com:389’
dn = ‘dddddddd’
pw = ‘xxxxxxx’
base_dn = ‘ou=People,o=oxccc.com,o=razor’
filter = ‘(objectclass=*)’
attrs = [‘idnumber’,‘emnumber’,‘givenname’,‘mail’]
con = ldap.initialize( host )
Bind to the server
con.simple_bind_s( dn, pw )
res = con.search_s( base_dn, ldap.SCOPE_SUBTREE, filter, attrs )
Close the connection
con.unbind()
Print the returned dictionary
#print res
row_list=res
for i in row_list:
print i[1]