Created
May 23, 2015 20:40
-
-
Save daboross/95023343fa8031bfbddd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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