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.
_______________________________________________
Please visit https://lists.isc.org/mailman/listinfo/bind-users to unsubscribe 
from this list

bind-users mailing list
bind-users@lists.isc.org
https://lists.isc.org/mailman/listinfo/bind-users

Reply via email to