Sponsored Content
Full Discussion: Perl dig script
Top Forums Shell Programming and Scripting Perl dig script Post 302966032 by timj123 on Saturday 6th of February 2016 04:20:32 PM
Old 02-06-2016
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.

Code:
#!/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:

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

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
Simple action in tc(8)                                                 Linux                                                Simple action in tc(8)

NAME
simple - basic example action SYNOPSIS
tc ... action simple [ sdata STRING ] [ index INDEX ] [ CONTROL ] CONTROL := { reclassify | pipe | drop | continue | ok } DESCRIPTION
This is a pedagogical example rather than an actually useful action. Upon every access, it prints the given STRING which may be of arbi- trary length. OPTIONS
sdata STRING The actual string to print. index INDEX Optional action index value. CONTROL Indicate how tc should proceed after executing the action. For a description of the possible CONTROL values, see tc-actions(8). EXAMPLES
The following example makes the kernel yell "Incoming ICMP!" every time it sees an incoming ICMP on eth0. Steps are: 1) Add an ingress qdisc point to eth0 2) Start a chain on ingress of eth0 that first matches ICMP then invokes the simple action to shout. 3) display stats and show that no packet has been seen by the action 4) Send one ping packet to google (expect to receive a response back) 5) grep the logs to see the logged message 6) display stats again and observe increment by 1 hadi@noma1:$ tc qdisc add dev eth0 ingress hadi@noma1:$tc filter add dev eth0 parent ffff: protocol ip prio 5 u32 match ip protocol 1 0xff flowid 1:1 action simple sdata "Incoming ICMP" hadi@noma1:$ sudo tc -s filter ls dev eth0 parent ffff: filter protocol ip pref 5 u32 filter protocol ip pref 5 u32 fh 800: ht divisor 1 filter protocol ip pref 5 u32 fh 800::800 order 2048 key ht 800 bkt 0 flowid 1:1 match 00010000/00ff0000 at 8 action order 1: Simple <Incoming ICMP> index 4 ref 1 bind 1 installed 29 sec used 29 sec Action statistics: Sent 0 bytes 0 pkt (dropped 0, overlimits 0 requeues 0) backlog 0b 0p requeues 0 hadi@noma1$ ping -c 1 www.google.ca PING www.google.ca (74.125.225.120) 56(84) bytes of data. 64 bytes from ord08s08-in-f24.1e100.net (74.125.225.120): icmp_req=1 ttl=53 time=31.3 ms --- www.google.ca ping statistics --- 1 packets transmitted, 1 received, 0% packet loss, time 0ms rtt min/avg/max/mdev = 31.316/31.316/31.316/0.000 ms hadi@noma1$ dmesg | grep simple [135354.473951] simple: Incoming ICMP_1 hadi@noma1$ sudo tc/tc -s filter ls dev eth0 parent ffff: filter protocol ip pref 5 u32 filter protocol ip pref 5 u32 fh 800: ht divisor 1 filter protocol ip pref 5 u32 fh 800::800 order 2048 key ht 800 bkt 0 flowid 1:1 match 00010000/00ff0000 at 8 action order 1: Simple <Incoming ICMP> index 4 ref 1 bind 1 installed 206 sec used 67 sec Action statistics: Sent 84 bytes 1 pkt (dropped 0, overlimits 0 requeues 0) backlog 0b 0p requeues 0 SEE ALSO
tc(8) tc-actions(8) iproute2 12 Jan 2015 Simple action in tc(8)
All times are GMT -4. The time now is 08:38 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy