30 lines
626 B
Python
30 lines
626 B
Python
|
#!/usr/bin/env python
|
||
|
|
||
|
import sys
|
||
|
import socket
|
||
|
import re
|
||
|
import dns.resolver
|
||
|
|
||
|
exp = re.compile('([^\.]+)')
|
||
|
|
||
|
if __name__ == '__main__':
|
||
|
|
||
|
|
||
|
for host in sys.stdin:
|
||
|
host = host.replace('\n', '')
|
||
|
if host == "" or host[0] == "#":
|
||
|
print(host)
|
||
|
continue
|
||
|
|
||
|
if host[0] == '!':
|
||
|
print(host[1:])
|
||
|
continue
|
||
|
|
||
|
try:
|
||
|
res = dns.resolver.query(host)
|
||
|
ip = socket.gethostbyname(str(res.qname))
|
||
|
|
||
|
print("{0}\t{1} {2}".format(ip, str(res.qname)[:-1], exp.match(host).group(0)))
|
||
|
except:
|
||
|
sys.stderr.write('Failed to get IP for: {0}\n'.format(host))
|