Python ldap 连接测试

标签 python testing active-directory connection ldap

我希望能够测试与主机和端口的连接是否有效。

我正在使用当前行:

ldapObject = ldap.open(host="host", port=389)

这似乎返回了一个实例。我需要确定它是否可以找到主机?

有什么建议吗?

最佳答案

open 已弃用。 这是一个工作示例。看看这是否有帮助。

def ldap_initialize(remote, port, user, password, use_ssl=False, timeout=None):
    prefix = 'ldap'
    if use_ssl is True:
        prefix = 'ldaps'
        # ask ldap to ignore certificate errors
        ldap.set_option(ldap.OPT_X_TLS_REQUIRE_CERT, ldap.OPT_X_TLS_NEVER)

    if timeout:
        ldap.set_option(ldap.OPT_NETWORK_TIMEOUT, timeout)

    ldap.set_option(ldap.OPT_REFERRALS, ldap.OPT_OFF)
    server = prefix + '://' + remote + ':' + '%s' % port
    conn = ldap.initialize(server)
    conn.simple_bind_s(user, password)
    return conn

关于Python ldap 连接测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21477272/

相关文章:

asp.net - 尝试通过ASP.NET更改AD中的密码 "user must change"

python - Python 中的递归回溯——在秤上平衡重量

c# - 将图像转换为要绘制的线条数组

java - 测试与外部服务的连接

powershell - 相当于 gpresult/r 与 powershell 没有广告模块

powershell - 更新 AD 用户帐户的职位和部门

python - GitPython 标签排序

python - 从 Python 中的 Sqlite 查询发送 JSON 响应

android - 如何将蓝牙数据发送到未知设备?

android - 是否可以以编程方式运行 InstrumentationTestRunner?