0

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)
7
  • I'd say grep "10\.0\.0\.1" zonefile but maybe i misunderstood the question
    – user130370
    Aug 10, 2012 at 12:29
  • Eric DANNIELOU: did you try actually grepping it and comparing with the expexted result ?
    – mykhal
    Aug 10, 2012 at 12:31
  • No. I guess there will be some issues. But did I understand the question correctly? I was afraid you have no direct access to zonefile
    – user130370
    Aug 10, 2012 at 12:36
  • Eric DANNIELOU: yes, we have that zone file.. how it could be done with following the condition not using any DNS server at all ?
    – mykhal
    Aug 10, 2012 at 12:38
  • What's missing you (except ipv6) in the script you posted? I got the expected result (5 hosts)
    – user130370
    Aug 10, 2012 at 13:51

1 Answer 1

3

It can't be done unless there's a reverse DNS entry for each one. Sure some people will tell you that it can be done and will even point you to a bunch of web sites that claim to do it but the fact is that it's just not possible.

6
  • err, in t he meantime, i've made little script, which does it (can't handle wildcards yet) - it's about text processing and relation evaluation.. maybe i should have formulated the question better
    – mykhal
    Aug 10, 2012 at 12:25
  • @mykhal, No you haven't. All you've created is a script that for some tests will appear to be successful. That's like the weather office getting it right one day. It doesn't mean they'll get it right every day. Aug 10, 2012 at 12:31
  • John Gardeniers: ok, what if i don't want REAL reverse lookup, but to find hostnames, which would resolve to given IP?
    – mykhal
    Aug 10, 2012 at 12:33
  • Do you have any idea how many hostnames there are? No. It can't be done. It really is that simple. Aug 10, 2012 at 12:37
  • John Gardeniers: this one is only 7 lines long, as you can see. the question is dealing single 1st level domain, with zone file available (i have updated the question, for clarity)
    – mykhal
    Aug 10, 2012 at 12:41

Not the answer you're looking for? Browse other questions tagged .