Created
June 8, 2014 16:07
-
-
Save u1735067/4a327f3bd69c4255b685 to your computer and use it in GitHub Desktop.
WhoisResEl
This file contains hidden or 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
#!python3 | |
import sys | |
import socket | |
import dns.resolver | |
import ipaddress | |
import re | |
socket.setdefaulttimeout(1) | |
resolver = dns.resolver.Resolver() | |
resolver.timeout = 1 | |
resolver.lifetime = 1 | |
print('\tWhoisResEl') | |
while True: | |
if (len(sys.argv) > 1): | |
addr = sys.argv[1] | |
else: | |
try: | |
addr=input('--IP/Host> ').strip() | |
except: # EOFError: | |
sys.exit(0) | |
if (addr == 'q'): | |
sys.exit(0) | |
if (not len(addr)): | |
continue | |
try: | |
addr=ipaddress.ip_address(addr) | |
host=socket.gethostbyaddr(str(addr))[0] | |
except ValueError: | |
if (re.match('^[a-zA-Z0-9\.-]+$', addr)): # "Valid" hostname | |
host = addr | |
else: | |
print('IP/Hostname invalide') | |
continue | |
except socket.herror: # Reverse resovl failed | |
print('Domaine introuvable') | |
continue | |
print('Host\t: '+host) | |
for qtype in ('A','AAAA','TXT'): | |
try: | |
for record in resolver.query(host, qtype): | |
try: | |
for elt in record.strings: | |
print(qtype+'\t: '+elt) | |
except AttributeError: | |
print(qtype+'\t: '+str(record)) | |
except Exception as e: | |
print(qtype+'\t: '+e.__class__.__name__) | |
if (len(sys.argv) > 1): | |
break | |
else: | |
print() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment