-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathad_lookup.py_prep_Python
More file actions
145 lines (109 loc) · 3.48 KB
/
ad_lookup.py_prep_Python
File metadata and controls
145 lines (109 loc) · 3.48 KB
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
###########################################################
#
# Copyright (c) 2005-2009, Southpaw Technology
# All Rights Reserved
#
# PROPRIETARY INFORMATION. This software is proprietary to
# Southpaw Technology, and is not to be reproduced, transmitted,
# or disclosed in any way without written permission.
#
#
#
__all__ = ['ADLookup', 'ADException']
import os
from pyasm.common import TacticException
class ADException(TacticException):
pass
ERROR = ""
try:
import win32security, pywintypes
import active_directory
except ImportError, e:
if os.name != 'nt':
ERROR = "Active directory libraries only work on a Windows platform"
else:
ERROR = 'Cannot import Win32 modules'
class ADLookup(object):
def __init__(my):
my.debug_flag= False
my.domain=""
my.filter=""
my.object=""
if ERROR:
raise ADException(ERROR)
def set_domain(my, domain):
my.domain = domain
my.debug("Setting domain to %s" % my.domain)
def set_debug(my, bool):
my.debug_flag=True
def set_ldap_string(my, ldapstring):
my.ldap_string=ldapstring
def get_root(my):
return active_directory.root()
def set_object(my, object):
my.object=object
def set_filter(my, filter):
my.filter=filter
def debug(my, message):
if my.debug_flag:
print message
def lookup_attr(my, username, attr):
user=active_directory.find_user(username)
print user.attr
return user.attr
def lookup_name(my, username):
user=active_directory.find_user(username)
#print user.dump
#x=user.properties
#print x.cn
print user.cn
return user.cn
def lookup_user(my, username):
user=active_directory.find_user(username)
return user
import sys, getopt
def usage():
print "ADS lookup tool"
print "Usage: adslookup.py [Option]"
print "Check for ADS data"
print ""
print "-u <name> Look up the username 'name'"
print "-o <objectname> objectname - ex. \"displayName\""
print "-f <filter> filter - ex. \"objectName=person\""
print "-h, --help Display this message, and exit"
print "-i lookup root info"
print "-r execute the lookup"
print "-d Debug messages"
print ""
def main(argv):
try:
opts, args = getopt.getopt(argv, "o:f:u:hdcir", ["help"])
except getopt.GetoptError:
usage()
sys.exit(2)
#try:
if len(opts) > 0:
ads = ADLookup()
for opt, arg in opts:
if opt in ("-h", "--help"):
usage()
sys.exit()
elif opt == '-o':
ads.set_object(arg)
elif opt == '-f':
ads.set_filter(arg)
elif opt == '-i':
print ads.get_root()
elif opt == '-d':
ads.set_debug(True)
elif opt == '-r':
ads.lookup()
elif opt == '-u':
ads.lookup_name(arg)
else:
usage()
sys.exit()
else:
print ("Try 'adslookup.py -h' for more information.")
if __name__ == '__main__':
main(sys.argv[1:])