home *** CD-ROM | disk | FTP | other *** search
/ Skunkware 98 / Skunkware 98.iso / src / net / bind-contrib.tar.gz / bind-contrib.tar / contrib / misc / update_bindcache < prev    next >
Encoding:
Internet Message Format  |  1996-10-25  |  2.7 KB

  1. Path: vixie!news1.digital.com!nntp-hub2.barrnet.net!news.Stanford.EDU!bloom-beacon.mit.edu!news.kei.com!news.mathworks.com!tank.news.pipex.net!pipex!howland.reston.ans.net!xlink.net!noris.net!jat!not-4-mail
  2. From: Joachim Astel <achim@astel.com>
  3. Newsgroups: alt.sources
  4. Subject: Automate update of root.cache with dig/perl
  5. Date: 28 Aug 1995 06:07:42 +0200
  6. Lines: 86
  7. Message-ID: <41rfeeW6c7@astel.com>
  8. NNTP-Posting-Host: wiese.astel.com
  9. X-Newsreader: NN version 6.5.0
  10.  
  11. This perl script fetches the latest root name server entry from
  12. ns.internic.net, does a compare with the root.cache on your local
  13. system, refuses the internic entry in some suspicious cases, or
  14. otherwise it will check-in the old root.cache (with RCS's "ci"),
  15. and overwrite "root.cache" with new root nameserver information.
  16.  
  17. This perl script could be started by cron once every year or so.
  18.  
  19. System requirements:  "/usr/bin/dig", "ci".
  20.  
  21.  
  22. #!/usr/bin/perl
  23. # update_bindcache - written 1995 by Joachim Astel <achim@astel.com>
  24.  
  25. # Last updated: Sun Aug 27 23:04:07 MET DST 1995
  26.  
  27. $CACHEDIR = "/var/named";
  28. $CACHEFILE = "root.cache";
  29.  
  30. $DIG = "/usr/bin/dig";
  31. $MAXSTAMP = 1000000;
  32. $MINSTAMP = 50000;
  33.  
  34. open (CACHE, "$CACHEDIR/$CACHEFILE") || die "Cannot open $CACHEFILE: $!\n";
  35. while (<CACHE>) {
  36.     next if /^;/; next if /^$/; chop;
  37.     ($host, $stamp, $type, $data) = split(/\t/, $_, 4);
  38.     $type =~ tr/a-z/A-Z/;
  39.     if ($host eq "." && $type eq "NS") {
  40.         push (@origns, $data);
  41.     } elsif ($type eq "A") {
  42.         $host =~ tr/a-z/A-Z/;
  43.         $orighostip{$host} = $data;
  44.     }
  45. }
  46. close CACHE;
  47. open (DIG, "$DIG \@ns.internic.net ns .|") || die "Cannot dig: $!\n";
  48. while (<DIG>) {
  49.     next if /^;;/; next if /^$/;
  50.     push (@dig, $_);
  51.     next if /^;/; chop;
  52.     ($host, $stamp, $type, $data) = split(/\t/, $_, 4);
  53.     $type =~ tr/a-z/A-Z/;
  54.     die "Internic's timestamp is suspicious to me ($_)\n"
  55.         if ($stamp > $MAXSTAMP || $stamp < $MINSTAMP);
  56.     if ($host eq "." && $type eq "NS") {
  57.         push (@ns, $data);
  58.     } elsif ($type eq "A") {
  59.         $host =~ tr/a-z/A-Z/;
  60.         $hostip{$host} = $data;
  61.     } else {
  62.         chop;
  63.         die "Internic's output is suspicious to me ($_)\n";
  64.     }
  65. }
  66. close DIG;
  67. $missing = 0;
  68. foreach (sort @origns) {
  69.     if ($hostip{$_} eq "") {
  70.         warn "Remove $_ [", $orighostip{$_}, "]\n";
  71.         $missing++;
  72.     }
  73. }
  74. $changes = 0;
  75. foreach (sort @ns) {
  76.     if ($orighostip{$_} eq "") {
  77.         warn "Create $_ [", $hostip{$_}, "]\n";
  78.         $changes++;
  79.     } elsif ($orighostip{$_} ne $hostip{$_}) {
  80.         warn "Change $_ [", $orighostip{$_},
  81.         "] -> [", $hostip{$_}, "]\n";
  82.         $changes++;
  83.     }
  84. }
  85. if ($missing) {
  86.     die "-- Please update your $CACHEFILE file manually.\n";
  87. }
  88. exit 0 unless $changes;
  89.  
  90. chdir ($CACHEDIR);
  91. system("yes . | ci -q -l $CACHEFILE");
  92. open(CACHE, ">$CACHEDIR/$CACHEFILE") || die "Can't write $CACHEFILE: $_\n";
  93. foreach (@dig) {
  94.     print CACHE $_;
  95. }
  96. close CACHE;
  97.