网络监控ping

时间:2014-07-16 23:30:27

标签: bash loops

我正在从一个txt文件中读取几百个ip地址,想要将列表ping到文件的末尾。希望这个在循环中运行,读到文件的末尾,然后再次从第一个地址开始。

trap 'echo ****Interrupted****; exit'INT

echo -n "Enter the file name with the ip addresses"
read file

echo -n "Enter the file name for the log file"
read log

while read line
do
echo "pinging: "$line
echo -e "">>$log
echo -n "NEXT PING: ">>$log
echo -n "$line" : " >>$log
$ping -c 3 -W 2 $line >>$log
done <"$file"

1 个答案:

答案 0 :(得分:0)

使用fping

http://fping.org/

来自fping手册页:

DESCRIPTION
   fping  is  a  program  like ping(8) which uses the Internet Control Message 
   Protocol (ICMP) echo request to determine if a target host is responding.
   fping differs from ping in that you can specify any number of targets on the 
   command line, or specify a file containing the lists of targets to ping.
   Instead  of  sending  to  one target until it times out or replies, fping will
   send out a ping packet and move on to the next target in a round-robin
   fashion.