2016-03-29 11:56:58 +00:00
|
|
|
import socket
|
2018-09-26 17:27:17 +00:00
|
|
|
from src import ModuleManager, Utils
|
2016-03-29 11:56:58 +00:00
|
|
|
|
2018-09-26 17:27:17 +00:00
|
|
|
class Module(ModuleManager.BaseModule):
|
2016-03-29 11:56:58 +00:00
|
|
|
_name = "DNS"
|
|
|
|
|
2018-09-26 17:27:17 +00:00
|
|
|
@Utils.hook("received.command.dns", min_args=1, usage="<hostname>")
|
2016-03-29 11:56:58 +00:00
|
|
|
def dns(self, event):
|
2018-09-26 17:27:17 +00:00
|
|
|
"""
|
|
|
|
Get all addresses for a given hostname (IPv4/IPv6)
|
|
|
|
"""
|
2016-03-29 11:56:58 +00:00
|
|
|
hostname = event["args_split"][0]
|
|
|
|
try:
|
|
|
|
address_info = socket.getaddrinfo(hostname, 1, 0,
|
|
|
|
socket.SOCK_DGRAM)
|
|
|
|
except socket.gaierror:
|
|
|
|
event["stderr"].write("Failed to find hostname")
|
|
|
|
return
|
|
|
|
ips = []
|
|
|
|
for _, _, _, _, address in address_info:
|
|
|
|
ips.append(address[0])
|
|
|
|
event["stdout"].write("%s: %s" % (hostname, ", ".join(ips)))
|