diff -r 78c87a54521e -r 146563ba991e dns-tool.pl --- a/dns-tool.pl Thu Nov 20 18:16:17 2008 +0000 +++ b/dns-tool.pl Fri Nov 21 12:46:27 2008 +0000 @@ -4,17 +4,34 @@ use warnings; use Pod::Usage; use File::Basename; +use Getopt::Long; my $ME = basename $0; +my $opt_delete = 0; my $opt_ttl = 3600; +my $opt_help; +my $opt_man; + my $opt_domain; my $opt_resolv = "/etc/resolv.conf"; MAIN: { + + GetOptions( + "d|delete" => \$opt_delete, + "ttl=i" => \$opt_ttl, + "help" => sub { pod2usage(-verbose => 1, exit => 0) }, + "man" => sub { pod2usage(-verbose => 2, exit => 0) }, + ) or pod2usage(); pod2usage() if @ARGV == 0; + die "HH"; + + my @out; + my $action = $opt_delete ? "delete" : "add"; + if (!$opt_domain) { local @ARGV = ($opt_resolv); $opt_domain = (split " ", (grep /^\s*(?:domain|search)\s+/, <>)[-1])[1]; @@ -28,15 +45,17 @@ pod2usage() if !@aliases and not $ip; - print "update add $host $opt_ttl CNAME $_\n" foreach @aliases; - print "update add $host $opt_ttl A $ip\n" if defined $ip; - print "send\n"; + push @out, "update $action $_ $opt_ttl CNAME $host" foreach @aliases; + push @out, "update $action $host $opt_ttl A $ip" if defined $ip; + push @out, "send" if @out; if ($ip) { my $rev_ip = (join ".", reverse split /\./, $ip) . ".in-addr.arpa"; - print "update add $rev_ip $opt_ttl PTR $host\n" - . "send\n"; + push @out, "update $action $rev_ip $opt_ttl PTR $host", + "send"; } + + print join "\n", @out, ""; } __END__ @@ -47,13 +66,49 @@ =head1 SYNOPSIS - dns-tool host[:alias:...] ip - dns-tool host:alias:... + dns-tool [-d|--delete] [--ttl=] host[:alias:...] ip + dns-tool [-d|--delete] [--ttl=] host:alias:... =head1 DESCRIPTION +This tool helps you using C, it doesn't update anything itself, it just +produces output suitable for C. + +=head2 EXAMPLES + + dns-tool seb-pc3454:lohn 172.20.2.2 | nsupdate + =head1 OPTIONS +=over + +=item B<-d>|B<--delete> + +Instead of adding, B the items. (default: off) + +=item B<--ttl>=I + +Set the TTL (unit: seconds) of the inserted records (default: 3600) + +=item B<-h>|B<--help> +=item B<-m>|B<--man> + +Help resp. manual page. + +=back + + + +=head1 COPYRIGHT, VERSION and AUTHOR + +This tool is released under terms of Gnu Public License in its +current version. + + $Id$ + $URL$ + + Heiko Schlittermann + =cut # vim:sts=4 sw=4 aw ai sm: