Perl dig script

Experts - I was hoping someone could help me out with the logic on this perl script.
I'm trying to run some dig commands and parse in such a way as to group them together.

Here's what I have so far.

#!/usr/bin/perl


system(clear);

my @host = qw/yahoo.com
google.com
/;

 foreach $i (@host) {
   $site{$i}=[];
   my @output = qx/dig -t aaaa +noall +answer $i/;
   push @{$site{$i}}, @output;
 }

 foreach $j (sort keys %site) {
   $site{$j}[1]=[];
   my @aaaa = @{$site{$j}};
     for $ip (@aaaa) {
       my @IP = split /\s+/,$aaaa[$ip];
       my @pingout = qx/ping6 -c3 $IP[4]/;

     }
   push @{$site{$j}[1]},@pingout;
 }

I'm trying to create a list like the following:

yahoo.com
    yahoo.com.		77	IN	AAAA	2001:4998:44:204::a7
      PING 2001:4998:44:204::a7(2001:4998:44:204::a7) 56 data bytes
      64 bytes from 2001:4998:44:204::a7: icmp_seq=1 ttl=52 time=90.9 ms

      --- 2001:4998:44:204::a7 ping statistics ---
      1 packets transmitted, 1 received, 0% packet loss, time 0ms
      rtt min/avg/max/mdev = 90.918/90.918/90.918/0.000 ms
    yahoo.com.		77	IN	AAAA	2001:4998:58:c02::a9
      PING 2001:4998:58:c02::a9(2001:4998:58:c02::a9) 56 data bytes
      64 bytes from 2001:4998:58:c02::a9: icmp_seq=1 ttl=48 time=92.8 ms

      --- 2001:4998:58:c02::a9 ping statistics ---
      1 packets transmitted, 1 received, 0% packet loss, time 0ms
      rtt min/avg/max/mdev = 92.878/92.878/92.878/0.000 ms
    yahoo.com.		77	IN	AAAA	2001:4998:c:a06::2:4008
      PING 2001:4998:c:a06::2:4008(2001:4998:c:a06::2:4008) 56 data bytes
      64 bytes from 2001:4998:c:a06::2:4008: icmp_seq=1 ttl=49 time=120 ms

      --- 2001:4998:c:a06::2:4008 ping statistics ---
      1 packets transmitted, 1 received, 0% packet loss, time 0ms
      rtt min/avg/max/mdev = 120.716/120.716/120.716/0.000 ms

google.com
    google.com.		182	IN	AAAA	2607:f8b0:4007:806::200e
      PING 2607:f8b0:4007:806::200e(2607:f8b0:4007:806::200e) 56 data bytes
      64 bytes from 2607:f8b0:4007:806::200e: icmp_seq=1 ttl=56 time=62.4 ms

      --- 2607:f8b0:4007:806::200e ping statistics ---
      1 packets transmitted, 1 received, 0% packet loss, time 0ms
      rtt min/avg/max/mdev = 62.458/62.458/62.458/0.000 ms

Does anyone have any advice on this?
Thanks in advance.

Just a suggestion.

#!/usr/bin/perl
# digin.pl

use strict;
use warnings;

my @domains = qw(
    yahoo.com
    google.com
);

for my $query (@domains) {
   print "$query\n";
   my @answers = qx{dig -t aaaa +noall +answer $query};
   for my $entry (@answers){
       printf "  %s", $entry;
       my $ipv6 = (split /\s+/, $entry)[4];
       my @pingout = qx{ping6 -c3 $ipv6};
       for my $lineout (@pingout){
           printf "    %s", $lineout;
       }
   }
   print "\n";
}

Output is with ipv4 since I do not use ipv6.

perl digin.pl
yahoo.com
  yahoo.com.            144     IN      A       98.138.253.109
    PING 98.138.253.109 (98.138.253.109) 56(84) bytes of data.
    64 bytes from 98.138.253.109: icmp_seq=1 ttl=51 time=63.1 ms
    64 bytes from 98.138.253.109: icmp_seq=2 ttl=51 time=54.6 ms
    64 bytes from 98.138.253.109: icmp_seq=3 ttl=51 time=51.0 ms

    --- 98.138.253.109 ping statistics ---
    3 packets transmitted, 3 received, 0% packet loss, time 2003ms
    rtt min/avg/max/mdev = 51.068/56.291/63.112/5.052 ms
  yahoo.com.            144     IN      A       206.190.36.45
    PING 206.190.36.45 (206.190.36.45) 56(84) bytes of data.
    64 bytes from 206.190.36.45: icmp_seq=1 ttl=47 time=52.0 ms
    64 bytes from 206.190.36.45: icmp_seq=2 ttl=47 time=56.0 ms
    64 bytes from 206.190.36.45: icmp_seq=3 ttl=47 time=56.6 ms

    --- 206.190.36.45 ping statistics ---
    3 packets transmitted, 3 received, 0% packet loss, time 2002ms
    rtt min/avg/max/mdev = 52.075/54.912/56.644/2.022 ms
  yahoo.com.            144     IN      A       98.139.183.24
    PING 98.139.183.24 (98.139.183.24) 56(84) bytes of data.
    64 bytes from 98.139.183.24: icmp_seq=1 ttl=51 time=84.8 ms
    64 bytes from 98.139.183.24: icmp_seq=2 ttl=51 time=90.2 ms
    64 bytes from 98.139.183.24: icmp_seq=3 ttl=51 time=89.3 ms

    --- 98.139.183.24 ping statistics ---
    3 packets transmitted, 3 received, 0% packet loss, time 2003ms
    rtt min/avg/max/mdev = 84.845/88.155/90.265/2.382 ms

google.com
  google.com.           300     IN      A       216.58.217.46
    PING 216.58.217.46 (216.58.217.46) 56(84) bytes of data.
    64 bytes from 216.58.217.46: icmp_seq=1 ttl=55 time=20.6 ms
    64 bytes from 216.58.217.46: icmp_seq=2 ttl=55 time=21.2 ms
    64 bytes from 216.58.217.46: icmp_seq=3 ttl=55 time=23.9 ms

    --- 216.58.217.46 ping statistics ---
    3 packets transmitted, 3 received, 0% packet loss, time 2003ms
    rtt min/avg/max/mdev = 20.637/21.949/23.921/1.424 ms
1 Like

AWESOME, AWESOME, AWESOME!
Thanks!!!