This repository has been archived by the owner on Oct 8, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tinydns-notify.pl
67 lines (59 loc) · 2.02 KB
/
tinydns-notify.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/usr/bin/perl -w
#
# Extract zones and their nameservers from tinydns-data file(s) and
# send DNS "NOTIFY" requests to nameservers listed in notify-list
# The file "notify-list" must contain one nameserver per line
#
# Written 2001-02-20 by Andrew Pam <[email protected]>
# Modified 2002-08-22 to support records that define nameserver addresses
# Modified 2002-08-30 to support "." records as well as "&" records
# Modified 2008-04-02 by Brad Peczka <[email protected]> to support
# systems with secondary/multihomed IP addresses
# Copyright (c) 2001-02 Serious Cybernetics <http://www.sericyb.com.au/>
# Partially inspired by dnsnotify by Jos Backus and James Raftery
# Distribute and modify freely, providing attribution is preserved
use Socket;
use Net::DNS;
my @self = split /\//, $0;
die "Usage: $self[-1] zonefile [...]\n" unless $#ARGV >= 0;
my $myip = "1.2.3.4"; #your ip address goes here
my %notify;
open(LIST, "notify-list") or die "Can't open notify-list file\n";
while (<LIST>)
{
($_) = split;
my $server = inet_aton $_ or (warn "$_ is not a valid server", next);
$notify{$server} = "";
}
close(LIST);
while (<>)
{
chomp;
my ($zone, $ip, $server) = /^[\&\.]([^:]*):([^:]*):([^:]*)/ or next;
$server = inet_aton ($ip || $server) or next;
$notify{$server} .= "$zone " if defined $notify{$server};
}
my $res = new Net::DNS::Resolver;
$res->srcaddr($myip);
my $op = 'NOTIFY';
eval { my $p = new Net::DNS::Packet; $p->header->opcode($op); };
$op = 'NS_NOTIFY_OP' if $@;
foreach $s (keys %notify)
{
next unless $_ = $notify{$s};
foreach (my @zone = split)
{
my $packet = new Net::DNS::Packet($_, "SOA", "IN");
die unless defined $packet;
($packet->header)->opcode($op);
($packet->header)->rd(0);
($packet->header)->aa(1);
my $server = inet_ntoa($s);
$res->nameservers($server);
$reply = $res->send($packet);
if (defined $reply)
{ print "Received NOTIFY answer for $_ from " . $reply->answerfrom . "\n"; }
else
{ warn "\$res->send indicates NOTIFY error for $server\n"; }
}
}