On Thu, 29 Oct 2009 10:38:56 -0500, Martin McCormick 
<mar...@dc.cis.okstate.edu> wrote:
> This is probably going to be a hashing exercise but I am checking to see
> if any of the building blocks needed are already out there.
> The problem is simple to describe in that there are 2 tables. One is a
> DNS zone transfer table of all the A or Address records in a given zone
> or from several zones for that matter.  the other table is from the same
> zones and consists of text or TXT records. The only thing the 2 tables
> have in common is that some of the TXT records share the exact same name
> field as the A records so we should be able to display the important
> contents of the A and TXT records on the same line if their names match.
> The challenge is to do this quickly so some sort of hash function is
> needed to locate A and TXT records having the same name.

Hi Martin,

You should use a Perl or Python script, and a hash...

If you show us a few sample lines from the input file and how you want the
output to look, it shouldn't be too hard to quickly hack one of those

With a short input file like this:

: keram...@kobe:/tmp$ cat input-file
: localhost       IN      A
: kobe            IN      A
: kobe            IN      TXT     "This is a test"

You can construct a hash map of hostname -> list of records in
Python with a relatively short script:

: #!/usr/bin/env python
: import re
: import sys
: are = None                      # a regexp for matching 'A' records
: txtre = None                    # a regexp for matching 'TXT' records
: try:
:     are = 
:     txtre = re.compile(r'^\s*(\S+)\s+[iI][nN]\s+[tT][xX][tT]\s+(.*)$')
: except Exception, inst:
:     sys.stderr.write('regexp error: %s' % str(inst))
:     sys.exit(1)
: hosts = {}
: for l in sys.stdin.readlines():
:     l = l.rstrip('\n\r')
:     # Is this an A record?
:     m = are.match(l)
:     if m:
:         (name, addr) = (m.group(1), m.group(2))
:         rec = ('A', addr)
:         if not name in hosts:
:             hosts[name] = [rec]
:         else:
:             hosts[name].append(rec)
:     # Is this a TXT record?
:     m = txtre.match(l)
:     if m:
:         (name, text) = (m.group(1), m.group(2))
:         rec = ('TXT', text)
:         if not name in hosts:
:             hosts[name] = [rec]
:         else:
:             hosts[name].append(rec)
: print hosts

Running this script should produce something like:

: keram...@kobe:/tmp$ python martin.py < input-file 
: {'kobe': [('A', ''), ('TXT', '"This is a test"')],
:  'localhost': [('A', '')]}

When you have the hash map of hostname to record-list for each host, you
can select and print any combination of host<=>record from this hash.

freebsd-questions@freebsd.org mailing list
To unsubscribe, send any mail to "freebsd-questions-unsubscr...@freebsd.org"

Reply via email to