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 :)

 

posted @ 2019-08-16 11:27  bigdog  阅读(1381)  评论(0编辑  收藏  举报