1、python连接server2016ad

2、使用389端口连接。

from ldap3 import Server, Connection, ALL, NTLM

# 输入域控地址,管理员账号密码
host_ip = '192.168.32.130'
admin_user = 'abcd\\administrator'
admin_password = '123.com'
# 创建server
server = Server(host=host_ip, get_info=ALL)
# 创建连接信息
conn = Connection(server, user=admin_user, password=admin_password, authentication=NTLM)
# 进行连接
conn.bind()
# 查看连接信息
print(conn)
# 关闭连接
conn.unbind()

# 出现以下证明连接成功,使用的是389
ldap://192.168.32.130:389 - cleartext - user: abcd\administrator - not lazy - bound - open - <local: 192.168.32.1:59272 - remote: 192.168.32.130:389> - tls not started - listening - SyncStrategy - internal decoder

Process finished with exit code 0

3、使用636端口连接

from ldap3 import Server, Connection, ALL, NTLM

# 输入域控地址,管理员账号密码
host_ip = '192.168.32.130'
admin_user = 'abcd\\administrator'
admin_password = '123.com'
# 创建server
server = Server(host=host_ip, get_info=ALL, use_ssl=True, port=636)
# 创建连接信息
conn = Connection(server, user=admin_user, password=admin_password, authentication=NTLM)
# 进行连接
conn.bind()
# 查看连接信息
print(conn)
# 关闭连接
conn.unbind()
# 出现以下证明连接成功,使用的是636
ldaps://192.168.32.130:636 - ssl - user: abcd\administrator - not lazy - bound - open - <local: 192.168.32.1:59308 - remote: 192.168.32.130:636> - tls not started - listening - SyncStrategy - internal decoder

Process finished with exit code 0

4、在使用修改域控用户密码需要安全连接,即636连接。