shell 校验IP地址

CheckIPAddress()        
{
        echo $1 > /tmp/tmpserverip
        echo $1 |grep "^[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}$" > /dev/null
        if [ $? = 1 ];    then
                return 1
        else
                a=$(cut -d. -f1 /tmp/tmpserverip)
                b=$(cut -d. -f2 /tmp/tmpserverip)
                c=$(cut -d. -f3 /tmp/tmpserverip)
                d=$(cut -d. -f4 /tmp/tmpserverip)
    
                for loop in $a $b $c $d
                do
                        if [ $loop -ge 255 ] || [ $loop -le 0 ]; then
                                return 2
                        fi
                done
        fi
            
        return 0
}

猜你喜欢

转载自edicky.iteye.com/blog/940056