daily pastebin goal
68%
SHARE
TWEET

Untitled

a guest Oct 3rd, 2017 82 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import ldap
  2. import os
  3. import re
  4.  
  5. def ad_search():
  6.     ldap_username = "使用者"
  7.     password = "密碼"
  8.     conn = ldap.initialize('ldap://伺服器位址')
  9.     conn.protocol_version = 3
  10.     conn.set_option(ldap.OPT_REFERRALS, 0)
  11.     conn.simple_bind_s(ldap_username, password)
  12.     basedn = "網域dn"                                                                                          # DC=456,DC=abc,DC=com,DC=tw
  13.     temp = conn.search_s(basedn,ldap.SCOPE_SUBTREE, "搜尋條件")        # 例如我要找我建的群組,搜尋條件就下 "(objectClass=organizationalUnit)"
  14.     for i in temp:
  15.         if i[0]:
  16.             t = re.search(r'(OU=\w+)', i[0])
  17.             yield t.group(0)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top