Created
September 19, 2019 00:08
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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