首页 > 代码库 > shell 验证ip

shell 验证ip

#!/bin/bashfunction isIp(){       IP=$1        if [ `echo $IP | awk -F . {print NF}` -ne 4 ];then                echo "Wrong IP!"                exit 2        else                a=`echo $IP | awk -F . {print $1}`                b=`echo $IP | awk -F . {print $2}`                c=`echo $IP | awk -F . {print $3}`                d=`echo $IP | awk -F . {print $4}`                if [[ $a -gt 0 && $a -le 255 ]] && [[ $b -ge 0 && $b -le 255 ]] && [[ $c -ge 0 && $c -le 255 ]] && [[ $d -gt 0 && $d -lt 255 ]];then                        #echo "Right IP!"                        return 0                        exit                else                       # echo "Wrong IP!"                       return 2                fi        fi}isIp "192.168.1.902"

 

shell 验证ip