#!/bin/bash
if [ $# != 3 ];thenecho "ip_test need three parameter ex > { ip_test arg1 arg2 arg3 }" && exit 1
fi
arg1=$(echo $1 | grep [^0-9])
arg2=$(echo $2 | grep [^0-9])
arg3=$(echo $3 | grep [^0-9])
if [ "$arg1" != "" ] || [ "$arg2" != "" ] || [ "$arg3" != "" ]; then
echo "arg must be positive integer, ex > { ip_test 25 1 220 }" && exit 2
fi
if [ "$1" -lt 0 ] || [ "$1" -gt 255 ]; then
echo "arg1 is invalid, need > { 0-255 }" && exit 3
fi
if [ "$2" -lt 0 ] || [ "$2" -gt 255 ];then
echo "arg2 is invalid, need > { 0-255 }" && exit 4
fi
if [ "$3" -lt 0 ] || [ "$3" -gt 255 ];then
echo "arg3 is invalid, need > { 0-255 }" && exit 5
fi
if [ "$2" -gt "$3" ];then
echo "arg2 cannt gt arg3, need > { arg2 <= arg3 }" && exit 6
fi
network="135.251.$1"
result=1
for (( hostid=$2; hostid<=$3; hostid=hostid+1 ))
do
ping -c 1 -w 1 ${network}.${hostid} > /dev/null && result=1 || result=0
if [ $result -eq 0 ];then
echo "ping ${network}.${hostid} failure"
fi
done
exit 0