mirror of https://github.com/n1nj4sec/pupy.git
Merge branch 'dns' of https://github.com/AlessandroZ/pupy
This commit is contained in:
commit
b40b56d013
|
@ -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)
|
|
@ -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
|
Loading…
Reference in New Issue