栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

如何使用Python更改域用户(Windows Active Directory)的密码?

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

如何使用Python更改域用户(Windows Active Directory)的密码?

这段代码适用于Windows 2012 R2 AD:

首先安装最新的ldap3软件包:sudo pip install ldap

#!/usr/bin/pythonimport ldap3SERVER='127.0.0.1'baseDN="DC=domain,DC=com"USER="user_domain_login_name@domain.com"CURREENTPWD="current_password"NEWPWD="new_password"SEARCHFILTER='(&(userPrincipalName='+USER+')(objectClass=person))'USER_DN=""USER_CN=""ldap_server = ldap3.Server(SERVER, get_info=ldap3.ALL)conn = ldap3.Connection(ldap_server, USER, CURREENTPWD, auto_bind=True)conn.start_tls()#print connconn.search(search_base = baseDN,         search_filter = SEARCHFILTER,         search_scope = ldap3.SUBTREE,         attributes = ['cn', 'givenName', 'userPrincipalName'],         paged_size = 5)for entry in conn.response:    if entry.get("dn") and entry.get("attributes"):        if entry.get("attributes").get("userPrincipalName"): if entry.get("attributes").get("userPrincipalName") == USER:     USER_DN=entry.get("dn")     USER_CN=entry.get("attributes").get("cn")print "Found user:", USER_CNprint USER_DNprint ldap3.extend.microsoft.modifyPassword.ad_modify_password(conn, USER_DN, NEWPWD, CURREENTPWD,  controls=None)


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/441351.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号