]>
Commit | Line | Data |
---|---|---|
3c456a5e | 1 | #!/usr/bin/perl -w |
2 | # | |
3 | # Extract zones and their nameservers from tinydns-data file(s) and | |
4 | # send DNS "NOTIFY" requests to nameservers listed in notify-list | |
5 | # The file "notify-list" must contain one nameserver per line | |
6 | # | |
7 | # Written 2001-02-20 by Andrew Pam <xanni@sericyb.com.au> | |
8 | # Modified 2002-08-22 to support records that define nameserver addresses | |
9 | # Modified 2002-08-30 to support "." records as well as "&" records | |
10 | # Copyright (c) 2001-02 Serious Cybernetics <http://www.sericyb.com.au/> | |
11 | # Partially inspired by dnsnotify by Jos Backus and James Raftery | |
12 | # Distribute and modify freely, providing attribution is preserved | |
13 | ||
14 | use Socket; | |
15 | use Net::DNS; | |
16 | ||
17 | my @self = split /\//, $0; | |
18 | die "Usage: $self[-1] zonefile [...]\n" unless $#ARGV >= 0; | |
19 | ||
20 | my %notify; | |
21 | open(LIST, "notify-list") or die "Can't open notify-list file\n"; | |
22 | while (<LIST>) | |
23 | { | |
24 | ($_) = split; | |
25 | my $server = inet_aton $_ or (warn "$_ is not a valid server", next); | |
26 | $notify{$server} = ""; | |
27 | } | |
28 | close(LIST); | |
29 | ||
30 | while (<>) | |
31 | { | |
32 | chomp; | |
33 | my ($zone, $ip, $server) = /^[\&\.]([^:]*):([^:]*):([^:]*)/ or next; | |
34 | $server = inet_aton ($ip || $server) or next; | |
35 | $notify{$server} .= "$zone " if defined $notify{$server}; | |
36 | } | |
37 | ||
38 | my $res = new Net::DNS::Resolver; | |
39 | ||
40 | foreach $s (keys %notify) | |
41 | { | |
42 | next unless $_ = $notify{$s}; | |
43 | foreach (my @zone = split) | |
44 | { | |
45 | my $packet = new Net::DNS::Packet($_, "SOA", "IN"); | |
46 | die unless defined $packet; | |
47 | ($packet->header)->opcode("NS_NOTIFY_OP"); | |
48 | ($packet->header)->rd(0); | |
49 | ($packet->header)->aa(1); | |
50 | my $server = inet_ntoa($s); | |
51 | $res->nameservers($server); | |
52 | $reply = $res->send($packet); | |
53 | if (defined $reply) | |
54 | { print "Received NOTIFY answer for $_ from " . $reply->answerfrom . "\n"; } | |
55 | else | |
56 | { warn "\$res->send indicates NOTIFY error for $server\n"; } | |
57 | } | |
58 | } |