diff -r 0c4905e5d01a -r 0d9901b561f7 lib/DNS/Vi.pm --- a/lib/DNS/Vi.pm Wed Jan 28 12:51:17 2015 +0100 +++ b/lib/DNS/Vi.pm Wed Jan 28 23:44:10 2015 +0100 @@ -5,14 +5,14 @@ use if $ENV{DEBUG} // '' eq 'dnsvi' => 'Smart::Comments'; use Digest::SHA qw(sha512_hex); use File::Temp; +use Net::DNS; use Term::ReadKey; use base 'Exporter'; use if $] >= 5.020, experimental => 'smartmatch'; -#no if $warnings::Offset{'experimental'} => (warnings => 'experimental'); - -our @EXPORT = qw(ttl2h h2ttl parse delta nice edit update show get_key); +our @EXPORT = qw(ttl2h h2ttl parse delta nice edit update show get_key + get_auth_info); our @EXPORT_OK = (); # the sort order for the records of the same label @@ -245,7 +245,7 @@ 'answer', ); if ($arg{-dry}) { - return say join "\n", '', @cmds, '' if $arg{-dry}; + return say join "\n", '', @cmds, '' if $arg{-dry}; } my @nsupdate = ( 'nsupdate', @@ -281,4 +281,26 @@ return $x; } +sub get_auth_info { + my $name = shift; + my %auth = (zone => undef, master => undef); + state $resolver = Net::DNS::Resolver->new; + my $response = $resolver->send($name, 'SOA') + or die $resolver->errorstring, "\n"; + +# use Data::Dumper; +# die Dumper $response; + + if (my @soa = grep { $_->type eq 'SOA' } $response->answer, $response->authority) { + die "got multiple soa records\n" if @soa > 1; + my $soa = $soa[0]; + return ( + name => $soa->name, + mname => $soa->mname, + ) + } + + return $response->authority; +} + 1;