此脚本提供所有用户数据(例如给定输出),但我想获取特定用户的 uid、uidnumber、mail、employeenumber。我怎么做?

This script gives all the users data (eg. given output) but I want to fetch specific user's uid, uidnumber, mail, employeenumber. How do I do that?

如何获取用户uid号、mail、employeenumber?

   ****Python Script*****
    
     



 from ldap3 import Server, Connection
            # clear connection
            my_server = 'XXX'
            my_user = 'uid=idmsa,ou=People,ou=auth,o=csun'
            my_password = 'password'
            
            s0 = Server(my_server)
            c0 = Connection(s0, my_user, my_password)
            c0.bind()
            c0.search("o=csun", "(cn=*)")
            print(c0.entries)

输出*

    DN: uid=aa22342,ou=People,ou=Auth,o=CSUN - STATUS: Read - READ TIME: 2021-06-24T10:27:10.169992

您可以传入要返回的属性列表:

c0.search("o=csun", "(cn=*)", attributes=['uid', 'uidNumber', 'mail'])

然后您可以使用以下方法迭代结果:

for entry in c0.response:
    print(entry['dn'])
    print(entry['attributes'])
    # ...

您可以在搜索中指定要返回的属性,默认为 none。

例如:

c0.search(search_base = 'o=csun',
     search_filter = '(cn=*)',
     search_scope = SUBTREE,
     attributes = ['uid', 'uidNumber', 'mail', 'employeeNumber'])

您可以在这里找到搜索功能的所有参数: https://ldap3.readthedocs.io/en/latest/searches.html