Sponsored Content
Full Discussion: Perl dig script
Top Forums Shell Programming and Scripting Perl dig script Post 302966035 by Aia on Saturday 6th of February 2016 06:26:20 PM
Old 02-06-2016
Just a suggestion.

Code:
#!/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.
Code:
perl digin.pl

Code:
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


Last edited by Aia; 02-06-2016 at 07:32 PM.. Reason: change @hosts for @domains for clarity
This User Gave Thanks to Aia For This Post:
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

dig

what is dig? Is it just a advanced type of nslookup? how to use it? //nicke:confused: (1 Reply)
Discussion started by: nicke30
1 Replies

2. UNIX for Dummies Questions & Answers

BIND and dig errors

Hi all, I'm running BIND 9.1.3 and the accompanying `dig and nslookup' on a vanilla Redhat 7.2 Linux box. I've produced all of my Zone data and config files (I used h2n with some manual tweaks to do this, as some >= v8.2 BIND features aren't properly supported as far as I can see). Im my... (6 Replies)
Discussion started by: sam_pointer
6 Replies

3. Shell Programming and Scripting

New to UNIX - what script to dig into to

First I would like to thank you for your time in running a great Forum! Background - Windows/ASP/VB COM/SQL Server programmer/Webmaster. Desire - To build similar skillset on UNIX. I am looking at learning Perl or Python (maybe Jython due to connection to Java). I have a brief background... (3 Replies)
Discussion started by: nimrod
3 Replies

4. UNIX for Dummies Questions & Answers

linux dig command

When I use the linux dig command such as #dig yahoo.com it resolves but when I use the same command as root it gives me error "Segmentation Fault" Please advise I am completly baffled. (1 Reply)
Discussion started by: Tirmazi
1 Replies

5. UNIX for Dummies Questions & Answers

Dig command output?

all, i am newbie to dns bind . Any help is very appreciated. I am using dig command to view the records in the config. I am expecting the following comamnds to display all the A (Address records) in the zone data file. my zone data file looks like this ------------------- $ORIGIN . $TTL... (2 Replies)
Discussion started by: sujathab
2 Replies

6. UNIX for Dummies Questions & Answers

dig query time

Hi Guys, I just need a confirmation if what think i know is right . dig yahoo.com ; <<>> DiG 9.7.0-P1 <<>> yahoo.com ;; global options: +cmd ;; Got answer: ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 27410 ;; flags: qr rd ra; QUERY: 1, ANSWER: 5, AUTHORITY: 0, ADDITIONAL: 0 ... (1 Reply)
Discussion started by: mtomar
1 Replies

7. IP Networking

The dig command

Can I use two different DNS servers in the one command in the form of primary and secondary. Take this for example: dig @<primaryAddress> @<secondaryAddress> MX domain.tld So if primary address is down, it will use the secondary address as a backup. It seems to work when testing, but thought... (1 Reply)
Discussion started by: neil_is_ere
1 Replies

8. UNIX for Advanced & Expert Users

DIG uses localhost

Hi, I have these entries in the /etc/esolv.conf: ------------ domain xxxxxx search yyyyyy nameserver 127.0.0.1 nameserver aaaaaaaaaaaaaaaa nameserver bbbbbbbbbbbbbbbb ------------- When I use 'dig' or 'nslookup' command, like 'dig yahoo.com' it uses the localhost as the server. I... (2 Replies)
Discussion started by: chaandana
2 Replies

9. IP Networking

DNS: Dig returns different responses...

Hey everyone, Okay, so I've been having some fun with the dig command, and wanted to dig my old school. Two questions came up from this. So I: dig @8.8.8.8 +recurse njcu.edu ANY and the result is about 8 records, including the SOA record. One of them is this weird TXT record, and the other is... (1 Reply)
Discussion started by: Lost in Cyberia
1 Replies

10. Shell Programming and Scripting

Dig match

Hi, I am testing some code to match a grep to see if one of the dns server exists but it does not seem to match: ERROR: ======= CRITICAL: google.com DNS : ns3.google.com NOT found CODE: ===== if ; then echo "OK: google.com DNS : ns3.google.com exists" else echo... (5 Replies)
Discussion started by: dmccabe
5 Replies
All times are GMT -4. The time now is 11:24 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy