From 5eb38cdf6cec2162b8c8260551ba1e0a1d474132 Mon Sep 17 00:00:00 2001 From: Alessandro ZANNI Date: Fri, 7 Oct 2016 17:54:24 +0200 Subject: [PATCH 1/2] getdomain controller main --- pupy/modules/getdomain.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 pupy/modules/getdomain.py diff --git a/pupy/modules/getdomain.py b/pupy/modules/getdomain.py new file mode 100644 index 00000000..a6712b73 --- /dev/null +++ b/pupy/modules/getdomain.py @@ -0,0 +1,19 @@ +# -*- coding: UTF8 -*- +from pupylib.PupyModule import * + +__class_name__="GetDomain" + +@config(compat="windows", cat="admin") +class GetDomain(PupyModule): + """ Get primary domain controller """ + + def init_argparse(self): + self.arg_parser = PupyArgumentParser(prog="getdomain", description=self.__doc__) + + def run(self, args): + self.client.load_package("pupwinutils.getdomain") + primary_domain = self.client.conn.modules["pupwinutils.getdomain"].get_domain_controller() + if not primary_domain: + self.error("This host is not part of a domain.") + else: + self.success("Primary domain controller: %s" % primary_domain) From 332eba32648abf3ed2aacad368e87bae4638e089 Mon Sep 17 00:00:00 2001 From: Alessandro ZANNI Date: Fri, 7 Oct 2016 17:54:43 +0200 Subject: [PATCH 2/2] get domain controller function --- pupy/packages/windows/all/pupwinutils/getdomain.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 pupy/packages/windows/all/pupwinutils/getdomain.py diff --git a/pupy/packages/windows/all/pupwinutils/getdomain.py b/pupy/packages/windows/all/pupwinutils/getdomain.py new file mode 100644 index 00000000..bbfedfb1 --- /dev/null +++ b/pupy/packages/windows/all/pupwinutils/getdomain.py @@ -0,0 +1,14 @@ +from _winreg import * + +def get_domain_controller(): + + aReg = ConnectRegistry(None, HKEY_LOCAL_MACHINE) + keypath = r"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Group Policy\\History\\" + subkey_name = 'DCName' + try: + aKey = OpenKey(aReg, keypath) + val, _ = QueryValueEx(aKey, subkey_name) + CloseKey(aKey) + return val + except: + return False