if __name__ __main__ ldap_server хост username teplov password pass us

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
if __name__ == "__main__":
ldap_server="хост"
username = "n.teplov"
password= "pass"
user_dn = "uid="+username+",ou=MAIL,dc=mail,dc=msk"
base_dn = "ou=MAIL,dc=mail,dc=msk"
connect = ldap.open(ldap_server)
search_filter = "uid="+username
try:
#if authentication successful, get the full user data
connect.bind_s(user_dn,password)
result = connect.search_s(base_dn,ldap.SCOPE_SUBTREE,search_filter)
# return all user data results
connect.unbind_s()
print result
except ldap.LDAPError:
connect.unbind_s()
print "authentication error"