一、环境准备:
系统:windows server 2012 r2标准版,添加Active Directionry域服务,DNS服务器,Active Directionary证书服务(证书颁发机构和证书颁发机构web注册,注意安装后需要配置,如下图),更改用户密码需要建立安全连接(ssl)需要Active Directionary证书服务
python版本:3.7,安装ldap3(pip install ldap3)
二、连接服务器
from ldap3 import Server, Connection, ALL
# host为域控服务器ip
server = Server(host, use_ssl=True, get_info=ALL)
# user(如domain\Administrator)和passwod为登录域控服务器的账户密码
conn = Connection(server, 'user', 'password', auto_bind=True)
三、查找对象
res = conn.search('dc=dctest,dc=com', '(objectclass=user)', attributes=['objec