Python作域用户验证登陆

安装包服务器

ldap3网络

 

代码:spa

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

 

注意:code

 Server('public.ad.com', get_info=ALL)这个黑黑的字符串,太难找到了,我问了很久,才从网络管理员那里拿到域控服务器的机器名Enjoy :)
相关文章
相关标签/搜索