Created
October 22, 2019 02:01
-
-
Save gjyoung1974/0c0748a5995a0b1ee4e534bccc8757a7 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#!/usr/bin/env python | |
import ldap | |
from utilities.conv_time import filetime_to_dt | |
# Instantiate LDAP object | |
l = ldap.initialize("ldap://1.1.1.1") | |
bind = l.simple_bind_s("[email protected]", "somePassw0rd") | |
l.protocol_version = ldap.VERSION3 | |
l.set_option(ldap.OPT_REFERRALS, 0) | |
# Get password last set | |
def get_pwd_last_set(ldap_obj, base, user): | |
criteria = "(&(objectClass=user)(sAMAccountName=" + user + "))" | |
attributes = ['pwdLastSet'] | |
result = ldap_obj.search_s(base, ldap.SCOPE_SUBTREE, criteria, attributes) | |
results = [entry for dn, entry in result if isinstance(entry, dict)] | |
return filetime_to_dt(int(results[0].get('pwdLastSet')[0])) | |
print(get_pwd_last_set(l, "OU=Users,DC=ad,DC=office", "gordon.young")) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment