home *** CD-ROM | disk | FTP | other *** search
/ PC-Online 1996 May / PCOnline_05_1996.bin / linux / source / n / bind / bind-4.001 / bind-4~ / bind-4.9.3-BETA9 / contrib / dnsparse / dnsmkptr < prev    next >
Text File  |  1990-09-11  |  2KB  |  46 lines

  1. #!/usr/bin/perl
  2. #
  3. # $Id: dnsmkptr,v 2.0 90/09/11 11:07:34 hakanson Rel $
  4. #
  5. # Convert DNS master (RFC-1035) file A records to PTR records.
  6. #   Marion Hakanson (hakanson@cse.ogi.edu)
  7. #   Oregon Graduate Institute of Science and Technology
  8. #
  9. # Copyright (c) 1990, Marion Hakanson.
  10. #
  11. # You may distribute under the terms of the GNU General Public License
  12. # as specified in the README file that comes with the dnsparse kit.
  13. #
  14. # Read the master files, and produce PTR records based on the A records
  15. # contained in them.  Note that if multiple names are found mapping to
  16. # a single address, we print out only the first mapping encountered.
  17. #
  18. # This is quite rudimentary, sorts the output by number, and does not
  19. # attempt to split the file by net or subnet number.  Hence it lumps
  20. # multiple domain zones into a single PTR zone file, and thus may be
  21. # less useful than it could be.
  22.  
  23. do "dnsparse.pl"; die "$@, aborted" if $@;
  24.  
  25. do dns_init(@ARGV);
  26.  
  27. open(OFILE, '| sort -n -t. +3 -4 +2 -3 +1 -2 +0 -1')
  28.     || die "Cannot start 'sort', aborted";
  29.  
  30. # bug -- can we guarantee this goes out first after being sorted?
  31. print OFILE "\$ORIGIN IN-ADDR.ARPA.\n";    # in case we get fed to a nameserver
  32.  
  33. rr: while ( (@rr = do dns_getrr()) && @rr ) {
  34.     ($domain, $ttl, $class, $type, @data) = @rr;
  35.  
  36.     next rr if ( $class ne 'IN' || $type ne 'A' );
  37.  
  38.     # only print out the first one
  39.     next rr if ( defined($addr{$data[0]}) );
  40.     
  41.     $addr{$data[0]} = 1;
  42.     
  43.     $revaddr = join('.',reverse(split(/\./, $data[0])));
  44.     print OFILE "$revaddr\tIN\tPTR\t$domain.\n";
  45. }
  46.