Responding with a subset of an rrset
G.W. Haywood
bind at jubileegroup.co.uk
Wed Apr 11 21:24:48 UTC 2018
Hi there,
On Wed, 11 Apr 2018, speijnik wrote:
> I'd need a way of returning a random pick of a limited number of
> records from a given rrset ...
Something like this?
8<----------------------------------------------------------------------
#!/usr/bin/perl -w
use strict;
use Net::DNS;
use List::Util qw( shuffle );
sub get_5_random_records
{
my $domain = shift;
my $rrtype = shift;
my @records = ();
my $resolver = Net::DNS::Resolver->new();
$resolver->nameservers( "ns.example.com" );
my $packet = $resolver->send( $domain, $rrtype );
if( ! $packet ) { return undef; }
my $packet_string = $packet->string();
if( $packet_string =~ m/NXDOMAIN/s ) { return undef; }
foreach my $rr ( $packet->answer() ) { if( $rr->type =~ /$rr/i ) { push @records, $rr->string; } }
my @shuffled = shuffle @records; # Not that they'll likely need it.
return splice( @shuffled, 0, 5 );
}
8<----------------------------------------------------------------------
Untested. Needs work. YMMV.
--
73,
Ged.
More information about the bind-users
mailing list