Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import ldap
- import os
- import re
- def ad_search():
- ldap_username = "使用者"
- password = "密碼"
- conn = ldap.initialize('ldap://伺服器位址')
- conn.protocol_version = 3
- conn.set_option(ldap.OPT_REFERRALS, 0)
- conn.simple_bind_s(ldap_username, password)
- basedn = "網域dn" # DC=456,DC=abc,DC=com,DC=tw
- temp = conn.search_s(basedn,ldap.SCOPE_SUBTREE, "搜尋條件") # 例如我要找我建的群組,搜尋條件就下 "(objectClass=organizationalUnit)"
- for i in temp:
- if i[0]:
- t = re.search(r'(OU=\w+)', i[0])
- yield t.group(0)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement