您可以dig +noall +answer -x <IP>
用来查找IP地址。
要简单地循环遍历包含IP地址列表的文件,请执行以下操作:
while read ip; do dig +noall +answer -x $ip; done < ips.txt
或者,通过管道传递计数命令的输出。这次我们分别获得计数和IP地址,然后将它们打印在一行上:
cat access.log | awk '{print $1}' | sort |
uniq -c | sort -n | tail -n10 |
while read count ip; do printf "%d " $count; printf "%s " $ip; dig +noall +answer -x $ip; done
示例(对不起,UUOC):
cat test | while read count ip; do printf "%d " $count; printf "%s " $ip; dig +noall +answer -x $ip; done
20 8.8.8.8 8.8.8.8.in-addr.arpa. 52767 IN PTR google-public-dns-a.google.com.
22 8.8.4.4 4.4.8.8.in-addr.arpa. 61369 IN PTR google-public-dns-b.google.com.
您可以将管道dig
的输出进一步管道到awk中,以获取主机名:
cat test | while read count ip; do printf "%d " $count; printf "%s " $ip; echo $(dig +noall +answer -x $ip | awk '{ print $(NF) }'); done
20 8.8.8.8 google-public-dns-a.google.com.
22 8.8.4.4 google-public-dns-b.google.com.