#!/bin/bash
x=0
for((host=1;host<=254;host++))
do
nmap -sP 192.168.1.$host | grep -q "is up"
if [ $? -eq 0 ] ;then
echo "host 192.168.1.$host is on line"
else
x=`expr $x + 1 `
fi
done
echo "不在线主机的个数是$x 台"
x=0
for((host=1;host<=254;host++))
do
nmap -sP 192.168.1.$host | grep -q "is up"
if [ $? -eq 0 ] ;then
echo "host 192.168.1.$host is on line"
else
x=`expr $x + 1 `
fi
done
echo "不在线主机的个数是$x 台"