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 :)
相關文章
相關標籤/搜索