Skip to content
Snippets Groups Projects

ldap_search_example

  • Clone with SSH
  • Clone with HTTPS
  • Embed
  • Share
    The snippet can be accessed without any authentication.
    Authored by Lauri Koivunen
    Edited
    find_tt_people.py 946 B
    import getpass
    import ldap3
    password=getpass.getpass()
    username=getpass.getuser()
    from ldap3 import Server, Connection, ALL
    import ssl
    from ldap3 import Tls
    from pprint import pprint
    server = Server('ldap.utu.fi', use_ssl=True)
    # Possibly alternatively: uid=specialusername,ou=Special Users,dc=utu,dc=fi
    conn = Connection(server,  "uid="+username+",ou=People,dc=utu,dc=fi", password, read_only=True, auto_range=False, )
    print("LDAP3 Helper",conn.bind(),conn.extend.standard.who_am_i())
    
    conn.search('cn=va26068_hlo,ou=Groups,dc=utu,dc=fi',
                            '(uniqueMember=*)',
                            attributes=['uniqueMember'])
    
    allmembers=conn.entries[0].uniqueMember
    
    for val in allmembers:
            print(val)
            conn.search(val,
                            '(uid=*)',
                            attributes=['cn', 'ou','title', 'uid', 'mail','mailAlternateAddress'])
            print(conn.entries)
    #print(server.info)
    #print(server.schema)
    0% Loading or .
    You are about to add 0 people to the discussion. Proceed with caution.
    Please register or to comment