Is there an existing tool or a cool or interesting way to find all items in DNS zone file, which are "resolving" to given IP? (not using any DNS server at all)
For instance, we might have following not very well organised DNS config:
example.org. 60 IN A 10.0.0.1
new.example.org. 60 IN A 10.0.0.10
www.example.org. 60 IN CNAME example.org.
old.example.org. 60 IN CNAME www.example.org.
toaster.example.org. 60 IN CNAME bigbox.example.org.
cutebox.example.org. 60 IN A new.example.org.
bigbox.example.org. 60 IN A 10.0.0.1
The tool's answer to the question: 10.0.0.1
should be the set example.org, www.example.org, old.example.org, toaster.example.org, bigbox.example.org
UPDATE: to be clear: we HAVE that zone file for the domain available
UPDATE: the following script which i've just kludged does almost exactly what i wanted (expects dns zone file on stdin) (no IPv6 support yet :-P) :
#! /usr/bin/env python
import re
import sys
cols = (0, 4)
type_col = 3
types = ('A', 'CNAME')
if len(sys.argv) != 2:
sys.exit('query not given (IP or hostname)')
query = sys.argv[1]
rex_not = re.compile(r'^\s*;')
relations = []
found = set([query])
def filter_pairs(l, f):
for itm in l:
if itm[1] in f: yield itm
in_pairs = []
for line in sys.stdin:
if rex_not.match(line): continue
itms = re.split(r'\s+', line.strip())
try:
typ = itms[type_col]
if typ not in types: continue
a, b = (itms[cols[0]], itms[cols[1]])
except IndexError: continue
if a and b: in_pairs.append((a, b))
oldpairs = in_pairs[:]
while True:
pairs = list(filter_pairs(in_pairs, found))
for itm in pairs: found.add(itm[0])
if len(pairs) == len(oldpairs): break
oldpairs = pairs
found = found.difference(set([query]))
for x in found: print(x)