Skip to content

Instantly share code, notes, and snippets.

@heywoodlh
Last active January 10, 2018 18:15
Show Gist options
  • Save heywoodlh/fd960a7803327470f24ae817cedd2e07 to your computer and use it in GitHub Desktop.
Save heywoodlh/fd960a7803327470f24ae817cedd2e07 to your computer and use it in GitHub Desktop.
Print base dn for Active Directory domain using Python
#!/usr/bin/env python3
domain = 'ad.domain.org'
bases = domain.split('.')
bases_total = len(bases)
global base_domain
base_domain = ''
run = 0
for base in bases:
if run == 0:
base_domain = 'dc=' + str(base)
elif bases.index(base) == bases_total - 1:
base_domain+='dc=' + str(base)
else:
base_domain+=',dc=' + str(base) + ','
run = run + 1
print('Base DN: ' + base_domain)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment