Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@teward
Created September 19, 2019 00:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save teward/9b3a5f2d57b11be75715b93e7c15c4e6 to your computer and use it in GitHub Desktop.
Save teward/9b3a5f2d57b11be75715b93e7c15c4e6 to your computer and use it in GitHub Desktop.
A rough perl script to wrap around a DNS resolver, to resolve domains passed into it via args and produces a list of A and AAAA records.
#!/usr/bin/env perl
use Net::DNS;
my $uri; # preinitialize $uri for use later
if (@ARGV <= 0 || @ARGV > 1) {
my $arglen = @ARGV || 0;
warn "We require ONE argument to be provided, " +
"you provided ", $arglen, ".\n";
} else {
$uri = $ARGV[0];
}
my $res = new Net::DNS::Resolver(recurse=>1, retry=>2, persistent_udp=>1);
my $reply = $res->search($uri, "A");
if ($reply) {
foreach my $rr ($reply->answer) {
print $rr->address, "\n" if $rr->can("address");
}
} else {
if (index($res->errorstring, "NOERROR") == -1) {
warn "[A] Record Lookup Error: ", $res->errorstring, "\n";
}
}
my $reply = $res->search($uri, "AAAA");
if ($reply) {
foreach my $rr ($reply->answer) {
print $rr->address, "\n" if $rr->can("address");
}
} else {
if (index($res->errorstring, "NOERROR") == -1) {
warn "[AAAA] Record Lookup Error: ", $res->errorstring, "\n";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment