37 lines
764 B
Python
37 lines
764 B
Python
import getpass
|
|
from ldap3 import Server, Connection, ALL, NTLM, ALL_ATTRIBUTES
|
|
|
|
print("Authentifizierung gegen ein Active Directory")
|
|
|
|
|
|
# Eingaben
|
|
dom = input("Domain [ADS1]:") or "ADS1"
|
|
user = input("User [hofmannol]:") or "hofmannol"
|
|
print('Password:', end='')
|
|
pwd = getpass.getpass()
|
|
|
|
# Binden an das AD
|
|
server = Server('gso1.ads1.fh-nuernberg.de', get_info=ALL)
|
|
conn = Connection(
|
|
server,
|
|
user=dom+"\\"+user,
|
|
password=pwd,
|
|
authentication=NTLM)
|
|
|
|
conn.bind()
|
|
print(conn)
|
|
print(conn.extend.standard.who_am_i())
|
|
print(conn.bound)
|
|
|
|
|
|
|
|
# Suche nach dem gerade verbundenen User
|
|
conn.search(
|
|
search_base='DC='+dom+',DC=fh-nuernberg,DC=de',
|
|
search_filter='(&(objectclass=user)(CN='+user+'))',
|
|
attributes=ALL_ATTRIBUTES)
|
|
print(conn.entries[0])
|
|
|
|
|
|
conn.unbind()
|