Search code examples
pythontestingactive-directoryconnectionldap

Python ldap connection test


I want to be able to test that a connection to a host and port is valid.

I'm using the current line:

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

This seems to return an instance. I need to determine if it can find the host or not?

Any suggestions?


Solution

  • Found a solution:

    import ldap
    
    try:
        ldapObject = ldap.open(host="host", port=389)
        ldapObject .simple_bind_s()
    except ldap.SERVER_DOWN:
        print("Failed")