我需要一些帮助与脚本,我试图得到一个域的所有域控制器列表。我正在使用python ldap3,尝试连接时出现错误。见下文,任何建议将不胜感激。
代码
#!/usr/bin/python3
from ldap3 import Server, Connection
# LDAP server configuration
ldap_server = 'ldap://company.com'
ldap_user = 'username'
ldap_password = 'mypassword'
# Connect to the LDAP server
server = Server(ldap_server, get_info=Server.info)
conn = Connection(server, ldap_user, ldap_password, auto_bind=True)
# Search for domain controllers
conn.search(search_base='CN=Domain Controllers,DC=company,DC=com',
search_filter='(objectClass=computer)',
attributes=['name'])
# Print the list of domain controllers
print("Domain Controllers:")
for entry in conn.entries:
print(entry.name)
输出
Traceback (most recent call last):
File "./query-dc-list4.py", line 13, in <module>
conn = Connection(server, ldap_user, ldap_password, auto_bind=True)
File "/usr/lib/python3.6/site-packages/ldap3/core/connection.py", line 356, in __init__
self._do_auto_bind()
File "/usr/lib/python3.6/site-packages/ldap3/core/connection.py", line 405, in _do_auto_bind
raise LDAPBindError(error)
1条答案
按热度按时间vm0i2vca1#
我刚刚意识到我的基础搜索是错误的。应该是以下内容