From b9181248ecfb6b021d9ca77a8f438d4753a2560f Mon Sep 17 00:00:00 2001 From: Alessandro ZANNI Date: Fri, 4 Nov 2016 15:53:19 +0100 Subject: [PATCH 1/3] add new module - resolve dns or ip address --- pupy/modules/dns.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 pupy/modules/dns.py diff --git a/pupy/modules/dns.py b/pupy/modules/dns.py new file mode 100644 index 00000000..d9a61868 --- /dev/null +++ b/pupy/modules/dns.py @@ -0,0 +1,21 @@ +# -*- coding: utf-8 -*- +from pupylib.PupyModule import * + +__class_name__="DNS" + +@config(cat="admin") +class DNS(PupyModule): + """ list system files """ + + def init_argparse(self): + self.arg_parser = PupyArgumentParser(prog="dns", description=self.__doc__) + self.arg_parser.add_argument('ip_or_domain', type=str, help='Domain name or IP address') + + def run(self, args): + self.client.load_package("pupyutils.dns") + functions = self.client.conn.modules["pupyutils.dns"].launch_dns_ip_resolver(args.ip_or_domain) + for function in functions: + if functions[function]['result']: + self.success('%s: %s' % (function, functions[function]['result'])) + else: + self.error('%s: Not found' % function) From e5afff9ae1ade523393da5e28d2fcb91a014bc25 Mon Sep 17 00:00:00 2001 From: Alessandro ZANNI Date: Fri, 4 Nov 2016 15:53:38 +0100 Subject: [PATCH 2/3] add new module functions - dns or ip address resolver --- pupy/packages/all/pupyutils/dns.py | 57 ++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 pupy/packages/all/pupyutils/dns.py diff --git a/pupy/packages/all/pupyutils/dns.py b/pupy/packages/all/pupyutils/dns.py new file mode 100644 index 00000000..b5396ec6 --- /dev/null +++ b/pupy/packages/all/pupyutils/dns.py @@ -0,0 +1,57 @@ +#!/user/bin/env python +import socket + +def getIP(domain): + """ + This method returns the first IP address string + that responds as the given domain name + """ + try: + return socket.gethostbyname(domain) + except Exception: + return False + +def getIPx(domain): + """ + This method returns an array containing + one or more IP address strings that respond + as the given domain name + """ + try: + return socket.gethostbyname_ex(domain)[2] + except Exception: + return False +# +def getHost(ip): + """ + This method returns the 'True Host' name for a + given IP address + """ + try: + return socket.gethostbyaddr(ip)[0] + except Exception: + return False +# +def getAlias(domain): + """ + This method returns an array containing + a list of aliases for the given domain + """ + try: + data = socket.gethostbyname_ex(domain) + alias = repr(data[1]) + return alias + except Exception: + return False + +def launch_dns_ip_resolver(ip_or_domain): + functions = { 'IP': {'function': getIP, 'result': ''}, + 'IPx': {'function': getIPx, 'result': ''}, + 'Host': {'function': getHost, 'result': ''}, + 'Alias': {'function': getAlias, 'result': ''} + } + + for function in functions: + functions[function]['result'] = functions[function]['function'](ip_or_domain) + + return functions \ No newline at end of file From 2077b9c872dc68d6deb71abe3889c86c9f27ed1a Mon Sep 17 00:00:00 2001 From: Alessandro ZANNI Date: Fri, 4 Nov 2016 17:54:52 +0100 Subject: [PATCH 3/3] changing module description --- pupy/modules/dns.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pupy/modules/dns.py b/pupy/modules/dns.py index d9a61868..89a7c669 100644 --- a/pupy/modules/dns.py +++ b/pupy/modules/dns.py @@ -5,7 +5,7 @@ __class_name__="DNS" @config(cat="admin") class DNS(PupyModule): - """ list system files """ + """ retrieve domain name from IP and vice versa """ def init_argparse(self): self.arg_parser = PupyArgumentParser(prog="dns", description=self.__doc__)