#!/bin/bash
#清空文件
>up.txt
>down.txt
#查看当前bash的pid号
echo $$
num=$(echo $$)
#查看过滤出当前子bash的父进程号
pstree -p|grep $num
#循环ping整个局域网里的ip地址
for i in {1..254}
do
#启动多进程去ping,提升效率,启动子进程放到后台去执行
(if ping -c 1 -W 1 192.168.174.$i &>/dev/null ;then
echo "192.168.174.$i is up"
else
echo "192.168.174.$i is down"
echo "192.168.174.$i" >>down.txt
fi)&
done
#等待子进程结束然后再退出
wait
#将arp缓存表里的记录保存到up.txt
arp -n |awk '/ether/{print $1,$3}' >up.txt