2016-03-29 11:56:58 +00:00
|
|
|
import socket
|
|
|
|
|
|
|
|
class Module(object):
|
|
|
|
_name = "DNS"
|
2018-09-02 18:54:45 +00:00
|
|
|
def __init__(self, bot, events, exports):
|
2018-09-19 12:25:12 +00:00
|
|
|
events.on("received.command.dns").hook(self.dns, min_args=1,
|
2016-04-06 11:02:44 +00:00
|
|
|
help="Get all addresses for a given hostname (IPv4/IPv6)",
|
|
|
|
usage="<hostname>")
|
2016-03-29 11:56:58 +00:00
|
|
|
|
|
|
|
def dns(self, event):
|
|
|
|
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)))
|