1
1
Fork 0

put everything in getmailad.py in a class

This commit is contained in:
David Starzengruber 2012-05-22 01:39:58 +02:00
parent d3018900e3
commit c50af138a7
1 changed files with 0 additions and 49 deletions

View File

@ -1,49 +0,0 @@
#!/usr/bin/python2 -B
""" ldap parser """
import ldap
ldap_server = "ldap://dc2.aec.at"
bind_dn = "david@aec.at"
bind_pass = "secret"
userbase = "ou=adm,dc=aec,dc=at"
keyword = "david"
def my_search(keyword):
result = instance.search_s(userbase, ldap.SCOPE_SUBTREE, ("cn=*"), ["mail", "proxyAddresses", "userAccountControl"])
return result
try:
instance = ldap.initialize(ldap_server)
bind = instance.simple_bind_s(bind_dn, bind_pass)
print "Successfully bound to server %s." %(ldap_server)
print "Searching..\n"
counter = 0
for item in my_search(keyword):
if item[1].has_key("userAccountControl"):
if item[1]["userAccountControl"] == ["512"] or item[1]["userAccountControl"] == ["66048"]:
if item[1].has_key("proxyAddresses"):
addresslist = item[1]["proxyAddresses"]
for address in addresslist:
if "SMTP:" in address or "smtp:" in address:
print address[5:].lower() + " OK"
counter += 1
print "objects: %s" %(counter)
except ldap.LDAPError, error_message:
print "Couldn't connect to server %s." %(ldap_server)
try:
instance.unbind()
print "Successfully unbound from server %s." %(ldap_server)
except ldap.LDAPError, error_message:
print "Couldn't unbind from server %s." %(ldap_server)
#end of file