Created
December 27, 2016 14:27
-
-
Save NorakGithub/ee654299aecfdfd471bdbaf73198211a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
>>> from ldap3 import Server, Connection, ALL | |
>>> server = Server('localhost', get_info=ALL) | |
>>> conn = Connection(server, 'cn=admin,dc=codium,dc=com', 'codium123', auto_bind=True) | |
>>> conn.search('dc=codium,dc=com', '(objectclass=person)') | |
True | |
>>> conn.entries | |
[DN: cn=Htet Naing Aung,ou=people,dc=codium,dc=com - STATUS: Read - READ TIME: 2016-12-27T21:23:11.662103 | |
, DN: cn=Than Htike Aung,ou=people,dc=codium,dc=com - STATUS: Read - READ TIME: 2016-12-27T21:23:11.662241 | |
] | |
>>> conn.add('cn=Noark,ou=people,dc=codium,dc=com', ['inetOrgPerson', 'organizationalPerson', 'person', 'top'], {'cn': 'Norak', 'sn': 'Khath', 'mail': 'norak@codium.com'}) | |
True | |
>>> conn.search('dc=codium,dc=com', '(objectclass=person)') | |
True | |
>>> conn.entries | |
[DN: cn=Htet Naing Aung,ou=people,dc=codium,dc=com - STATUS: Read - READ TIME: 2016-12-27T21:23:37.818382 | |
, DN: cn=Than Htike Aung,ou=people,dc=codium,dc=com - STATUS: Read - READ TIME: 2016-12-27T21:23:37.818484 | |
, DN: cn=Noark,ou=people,dc=codium,dc=com - STATUS: Read - READ TIME: 2016-12-27T21:23:37.818568 | |
] | |
>>> conn.search('dc=codium,dc=com', '(objectclass=person)', attributes=['sn', 'cn', 'mail']) | |
True | |
>>> conn.entries | |
[DN: cn=Htet Naing Aung,ou=people,dc=codium,dc=com - STATUS: Read - READ TIME: 2016-12-27T21:24:22.763037 | |
cn: Htet Naing Aung | |
mail: htetnaing_a@codium.com | |
sn: Aung | |
, DN: cn=Than Htike Aung,ou=people,dc=codium,dc=com - STATUS: Read - READ TIME: 2016-12-27T21:24:22.763219 | |
cn: Than Htike Aung | |
mail: thanhtikeaung@codium.com | |
sn: Aung | |
, DN: cn=Noark,ou=people,dc=codium,dc=com - STATUS: Read - READ TIME: 2016-12-27T21:24:22.763380 | |
cn: Norak | |
Noark | |
mail: norak@codium.com | |
sn: Khath | |
] | |
>>> print(conn.entries[0].entry_to_json) | |
<bound method EntryBase.entry_to_json of DN: cn=Htet Naing Aung,ou=people,dc=codium,dc=com - STATUS: Read - READ TIME: 2016-12-27T21:24:22.763037 | |
cn: Htet Naing Aung | |
mail: htetnaing_a@codium.com | |
sn: Aung | |
> | |
>>> print(entry.entry_to_json) | |
Traceback (most recent call last): | |
File "<stdin>", line 1, in <module> | |
NameError: name 'entry' is not defined | |
>>> print(conn.entries[0].entry_to_json()) | |
{ | |
"attributes": { | |
"cn": [ | |
"Htet Naing Aung" | |
], | |
"mail": [ | |
"htetnaing_a@codium.com" | |
], | |
"sn": [ | |
"Aung" | |
] | |
}, | |
"dn": "cn=Htet Naing Aung,ou=people,dc=codium,dc=com" | |
} | |
>>> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment