shell實戰之:通過ping批量解析網域名稱的DNS
01通過ping批量解析網域名稱的DNS02需求:從一個檔案中讀入網域名稱列表:031.讀取網域名稱列表檔案。04列表檔案格式為:051.cn062.cn072.將解析後的ip輸出到一個檔案中。08輸出的檔案格式為:09DNS: 1.cn 1.1.1.110DNS: 2.cn 2.2.2.211#!/bin/sh12#code by scpman13#write 2013-08-2214#ping test15echo > pingok.txt16echo > pingfaild.txt17#read ip list18for ip in `cat ip.txt`19do20#ping one21res=`ping -c 1 $ip | egrep "\(.*\)" | sed -e "s/PING/DNS:/g;s/(//g;s/): 56 data bytes//g" `22if [ `echo "$res"| grep -c 'DNS'` -gt 0 ]23then24 echo $res25 echo $res >> pingok.txt26else27 echo ping $ip fail28 echo $ip >> pingfaild.txt29fi 30done31儲存運行之:32# sh a.sh33DNS: www.expo-china.com 222.73.238.5134DNS: page.china.alibaba.com 110.75.195.1035DNS: ad6832e5c544c20f.cdn.jiashule.com 183.61.117.10336ping: cannot resolve www.d1net.comexpo: Unknown host37ping www.d1net.comexpo fail38DNS: www.youxiuhui.com 219.234.4.9039最後查看結果:40成功的41# cat pingok.txt42DNS: www.expo-china.com 222.73.238.5143DNS: page.china.alibaba.com 110.75.195.1044DNS: expo.asiapump.cn 222.73.57.5245。。。46# cat pingfaild.txt47www.d1net.comexpo48www.cecsz.net1