Python做域用户验证登录


安装包

ldap3

 

代码:

from ldap3 import Server, Connection, ALL, NTLM

# 连接
server = Server('public.ad.com', get_info=ALL)
str_user = 'demo.ad\\zhangxiaomeng'
str_password = 'DE201906#'
bool_haslogin =True
try:
    conn = Connection(server, user=str_user, password=str_password, auto_bind=True, authentication=NTLM)
except:
    bool_haslogin = False
    print("Error loging AD Server...")
else:
    print("Sucessfull loging AD!!!")


print(str(bool_haslogin))

 

注意:

 Server('public.ad.com', get_info=ALL)
这个黑黑的字符串,太难找到了,我问了好久,才从网络管理员那里拿到域控服务器的机器名

Enjoy :)

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM