//ping测试  检测局域网在线主机与不在线主机,并分别将它们打印出来

//并统计它们的数量



#!/bin/bash

#


//声明网络地址

host_pre="192.168.0"


//声明在线主机数量

declare -i active_sum=0

//声明不在线主机数量

declare -i unactive_sum=0


// for 循环执行ping主机测试

for i in {1..254}; do

if ping -c 1 -w 1 "$host_pre.$i" &>/dev/null; then

echo -e "33[32m [*] $host_c.$i is active. 33[0m"

//在线主机数量+1

active_sum=$active_sum+1

else

//不在线主机数量+1

echo -e "33[31m [!] $host_pre.$i is unactive. 33[0m"

unactive_sum=$unactive_sum+1


fi

done


//打印在线主机数量

echo -e "33[32m active number: $active_sum 33[0m"

//打印不在线主机的数量

echo -e "33[31m unactive number: $unactive_sum 33[0m"


exit 0