Friday, June 14, 2013

Check if a DN on a M$ Active Directory existed

I will use the ssh_client module I wrote ( to execute M$ Windows Active Directory command line remotely from my Ubuntu.

#! /usr/bin/python
import ssh_client

def dn_existed(dn, type_of_dn, ssh_client):

# type_of_dn is group, ou or user
command = 'dsget ' + type_of_dn + ' "' + dn + '"'

if 'succeeded' in ssh_client.return_str:
return True

return False

if __name__ == "__main__":
       client = ssh_client.MySSHClient()

       if dn_existed(dn, 'ou', client):
              print "Existed"
              print "Not existed"