if __name__ __main__ ldap_server 61 236 38 username teplov password 12

 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="5.61.236.38"
username = "n.teplov"
password= "!123qawsedvfhkb"
# the following is the user_dn format provided by the ldap server
user_dn = "uid="+username+",ou=MAIL,dc=mail,dc=msk"
# adjust this to your base dn for searching
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"