Advertisement
Cobble5tone

Ldap3 connection - Python

Aug 16th, 2019
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.71 KB | None | 0 0
  1. from ldap3 import Server
  2.  
  3. from ldap3 import Connection
  4.  
  5. from ldap3 import ALL
  6.  
  7. from ldap3 import NTLM
  8.  
  9. from ldap3 import SUBTREE
  10.  
  11. from ldap3 import ALL_ATTRIBUTES
  12.  
  13.  
  14.  
  15. ad_server = Server('Your domain name.int', use_ssl=True, get_info=ALL)
  16.  
  17. conn = Connection(ad_server, user='your domain\\ user name', password='password', authentication=NTLM)
  18.  
  19.  
  20.  
  21. if not conn.bind():
  22.     print('FAILED TO CONNECT')
  23.  
  24. else:
  25.     who = conn.extend.standard.who_am_i()
  26.  
  27.  
  28.  
  29.     people = conn.search('dc=your domain, dc=int', '(&(objectclass=group)(sAMAccountName= user login))',
  30.  
  31.                      search_scope=SUBTREE, attributes=ALL_ATTRIBUTES, get_operational_attributes=True)
  32.  
  33.  
  34. print(conn.entries)
  35. print(who)
  36. print(conn)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement