> On Jan 20, 2017, at 12:24 PM, al...@myfastmail.com wrote: > > For my domain, I retrieve its DNS A-records from a local nameserver using > > /usr/bin/dig -t A @192.0.2.1 -k /etc/named/keys/T.key +noadditional > +dnssec +multiline +norecurs example.com > > In my perl script, I can do the same using system() > > system( "/usr/bin/dig", "-t", "A", "\@192.0.2.1", "-k", > "/etc/named/keys/T.key", "+noadditional", "+multiline", "+norecurs", > "example.com" ); > > which lists all the keys to console. > > I want to get at the same info using Perl, with the results in objects that I > can extract data from and assign to variables. > > IIUC, Net::DNS is the right tool. > > Reading the docs I don't understand how I'd pass all those bind dig-specific > arguments to Net::DNS. > > What's the right syntax / usage for that query in Net::DNS?
You need to look at the documentation for the Net::DNS::Resolver, Net::DNS::Packet, and Net::DNS::Question modules as well as Net::DNS. I have not used these modules before, but from the documentation I can suggest something like this to get started: __CODE__ use strict; use warnings; use Net::DNS; my $url = 'www.google.com'; my $resolver = new Net::DNS::Resolver( nameservers => [ ‘192.0.2.1' ], recurse => 0, ); my $reply = $resolver->query($url) or die("Can't resolve $url $!"); my @question = $reply->question; print "Reply:\n"; $reply->print; __END__ It is possible that the Net::DNS family of modules do not support all of the options that the dig program does, but you will have to dig through the documentation and figure that out. For example, you can print out individual sections like this: print "\n;; HEADER SECTION\n"; $reply->header->print(); but I don’t see anything that supports an optional TSIG file equivalent to the -k option (I don’t know what that is, so can’t help with that). Good luck! Jim Gibson -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/