سؤال

I have all the IPs that I want to dig +trace -x in a file called 'ips'.

I want to only see the ns1 (and/or) ns2 records of the IP and and have the IP and the ns1 or ns2 record output on the same line, like so:

1 - $IP - $NS
2 - $IP - $NS
etc.

Right now, I only have a script I call 'digdug', which looks like this...

for i in `cat ips`
do
dig +trace -x $i | tail -n7
done

and then I am able to see the IP that it is digging by running: bash -x digdug

But, what I really need is the IP and the ns record on one line, then the next IP in the list with ns record on the next line. Then the next and so on.

Any help is greatly appreciated!

هل كانت مفيدة؟

المحلول

Perhaps something like this?

for ip in `cat ips`; do
  ns=`dig +trace -x $ip | tail -n7 | awk '/NS/ {print $NF}'`
  echo "$ip - $ns" | tr '\n' ' '
  echo ""
done

نصائح أخرى

another solution in bash 4 :

while read ip; do
    while read ns; do
       echo -e "$ip\t$ns";
    done < <(dig +trace -x $ip | grep -i "ns[12]")
done < ips

I prefer to use the while TEST; do CMD; done < file because it did not fork a subshell.

the < <(cmd) is for function substitution. Like the < redirection, bash do not create a subshell.

ex., here is a result on google IP (173.164.67.9[1-5]):

173.194.67.91   194.173.in-addr.arpa.   86400   IN      NS      NS1.GOOGLE.COM.
173.194.67.91   194.173.in-addr.arpa.   86400   IN      NS      NS2.GOOGLE.COM.
173.194.67.92   194.173.in-addr.arpa.   86400   IN      NS      NS2.GOOGLE.COM.
173.194.67.92   194.173.in-addr.arpa.   86400   IN      NS      NS1.GOOGLE.COM.
173.194.67.92   67.194.173.in-addr.arpa. 60     IN      SOA     ns1.google.com. dns-admin.google.com. 1497777 21600 3600 1209600 10800
173.194.67.93   194.173.in-addr.arpa.   86400   IN      NS      NS2.GOOGLE.COM.
173.194.67.93   194.173.in-addr.arpa.   86400   IN      NS      NS1.GOOGLE.COM.
173.194.67.94   194.173.in-addr.arpa.   86400   IN      NS      NS2.GOOGLE.COM.
173.194.67.94   194.173.in-addr.arpa.   86400   IN      NS      NS1.GOOGLE.COM.
173.194.67.95   194.173.in-addr.arpa.   86400   IN      NS      NS1.GOOGLE.COM.
173.194.67.95   194.173.in-addr.arpa.   86400   IN      NS      NS2.GOOGLE.COM.

hope this will help

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top