Accessing the LDAP server

Using ldap3 is straightforward—you define a Server object and a Connection object. All the importable objects are available in ldap3 namespace. You need to at least import the Server and the Connection object, and any additional constants you will use in your LDAP connection:

>>> from ldap3 import Server, Connection, ALL

In this example, we are accessing the LDAP server with an anonymous bind. The auto_bind=True parameter forces the Bind operation to execute after creating the Connection object. You can get information with the info property of the Server object.

You can find the following code in the connect_ldap_server.py file:

#!/usr/bin/env python3import argparsefrom ldap3 import Server, Connection, ALLdef main(address): ...

Get Learning Python Networking - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.