#!/bin/bash
#
2017年
8月
30日
#by lee
#auto test the ip
IP_ADDR=$
1
IP_DIR=
"ip.txt"
test_ipA(){
if [[ $1 -gt 254 ]] ||
[[ $1 -le 0 ]];
then
echo
"the ip is illegal"
exit
0
fi
}
test_ipB(){
if [[ $1 -gt 254 ]] ||
[[ $1 -lt 0 ]];
then
echo
"the ip is illegal"
exit
0
fi
}
echo $IP_ADDR > $IP_DIR
grep
if [[ $? -ne 0 ]];
then
echo
"the ip is illegal"
exit
0
else
a=`awk -F
"." '{print $1}' ${IP_DIR}`
#传递参数给函数
test_ipA
"$a"
b=`awk -F
"." '{print $2}' ${IP_DIR}`
test_ipB $b
c=`awk -F
"." '{print $3}' ${IP_DIR}`
test_ipB $c
d=`awk -F
"." '{print $4}' ${IP_DIR}`
test_ipA $d
echo
"the ip is legal"
fi