This commit is contained in:
n1nj4sec 2016-11-17 20:19:14 +01:00
commit b40b56d013
2 changed files with 78 additions and 0 deletions

21
pupy/modules/dns.py Normal file
View File

@ -0,0 +1,21 @@
# -*- coding: utf-8 -*-
from pupylib.PupyModule import *
__class_name__="DNS"
@config(cat="admin")
class DNS(PupyModule):
""" retrieve domain name from IP and vice versa """
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)

View File

@ -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