#!/bin/bash
#Program:
# This program to ping ip host
#History:
# 2021/1/30 feiniaopeng First release
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~bin
export PATH
network="192.168.1"
for hostid in {1..255} #也可以为$(seq1 255)
do
ping -c 1 -w 1 ${network}.${hostid} &> /dev/null && result=0 || result=1 # -c为探测次数,-w为探测时间
if [ "${result}" == 0 ] ;then
echo "the server ${network}.${hostid} is up"
else
echo "the server ${network}.${hostid} is down"
fi
done