Skip to content

Instantly share code, notes, and snippets.

@daboross
Created May 23, 2015 20:40
Show Gist options
  • Save daboross/95023343fa8031bfbddd to your computer and use it in GitHub Desktop.
Save daboross/95023343fa8031bfbddd to your computer and use it in GitHub Desktop.
import socket
from cloudbot import hook
@hook.command()
def dns(text):
"""<domain> - resolves the IP of <domain>"""
try:
socket.setdefaulttimeout(5)
ip = None
for info in socket.getaddrinfo(text, 80, 0, 0, socket.SOL_TCP):
print(info)
if ip is None:
ip = info[-1][0]
else:
ip = "{}, {}".format(ip, info[-1][0])
return "{} resolves to {}".format(text, ip)
except socket.gaierror:
return "Resolve Failed!"
@hook.command()
def host(text):
"""<ip> - Resolves the hostname of <ip>"""
try:
socket.setdefaulttimeout(5)
domain = socket.gethostbyaddr(text)[0]
return "{} resolves to {}".format(text, domain)
except (socket.gaierror, socket.error):
return "Resolve Failed!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment