This repository has been archived by the owner on Dec 10, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathad.py
39 lines (34 loc) · 1.57 KB
/
ad.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import ldap
import pandas
import datetime.datetime
from ldap_paged_search import LdapPagedSearch
host = 'ldaps://example.com:636'
username = 'domain\\username'
password = 'password'
baseDN = 'DC=example,DC=com'
filter = "(&(objectCategory=computer))"
#attributes = ['dn']
attributes = ['*']
#ldap.set_option(ldap.OPT_X_TLS_REQUIRE_CERT, ldap.OPT_X_TLS_NEVER)
l = LdapPagedSearch(host, username, password, maxPages=0, pageSize=1000)
results = l.search(baseDN, filter, attributes = attributes)
computers = []
for computer in results:
dn = computer[0]
try:operatingSystem = computer[1]['operatingSystem'][0]
except: operatingSystem = False
try: operatingSystemServicePack = computer[1]['operatingSystemServicePack'][0]
except: operatingSystemServicePack = False
hostname = computer[1]['cn'][0]
try: fqdn = computer[1]['dNSHostName'][0]
except: fqdn = False
whenCreated = computer[1]['whenCreated'][0]
try: lastLogonTimestamp = datetime.datetime.utcfromtimestamp((int(computer[1]['lastLogonTimestamp'][0]) - 116444736000000000) / 10000000)
except: lastLogonTimestamp = False
try: description = computer[1]['description'][0]
except: description = False
GUID = computer[1]['objectGUID'][0]
computers.append((dn,hostname,fqdn,operatingSystem,operatingSystemServicePack,whenCreated,lastLogonTimestamp,description,GUID))
comp = pandas.DataFrame(computers)
comp.columns = ['dn','hostname','fqdn','operatingSystem','operatingSystemServicePack','whenCreated','lastLogonTimestamp','description','GUID']
windows = comp[comp['operatingSystem'] != "Mac OS X"]