热门关键字:  ubuntu  分区  函数  Fedora  linux系统进程

当前位置 :| 主页>Linux教程>Shell开发>

shell输入 ip 合法性

来源: 作者: 时间:2008-01-04 Tag: 点击:

grep "^([01]?\d\d?|2[0-4]\d|25[0-5])\.([01]?\d\d?|2[0-4]\d|25[0-5])\.([01]?\d\d?|2[0-4]\d|25[0-5])\.([01]?\d\d?|2[0-4]\d|25[0-5])\.$"

 

输入ip,检查其是否满足的ip书写规范,即不能大于255,不能有字母,和其他标点,参考网上的,自己搞了个如下,做个标记!@

echo -n 'Enter the Server-ip:'
        read BISSip
        echo $BISSip > /tmp/tmpserverip
        echo $BISSip|grep "^[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}$" > /dev/null
        num=$?
        if [ $num = 1 ]
        then
                echo error ip,please enter correct
       
        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)
   
        {
                if [ $a -ge 255 ]||[ $a -le 0 ]
                then
                        echo a:error ip
                else
                        echo 1 > /tmp/jack
                 fi
        }
   
        {
                if [ $b -ge 255 ]||[ $b -lt 0 ]
                then
                        echo b:error ip
        else
                        echo 1 >>/tmp/jack
        fi
   
        }
    
        { if [ $c -ge 255 ]||[ $c -lt 0 ]
                 then
                         echo c:error ip
                else
                        echo 1 >>/tmp/jack
                    fi
         }
   
         { if [ $d -ge 255 ]||[ $d -le 0 ]
                then
                        echo d:error ip
                else
                        echo 1 >> /tmp/jack
                fi
         }


最新评论共有 4 位网友发表了评论
发表评论
评论内容:不能超过250字,需审核,请自觉遵守互联网相关政策法规。
用户名: 密码:
匿名?
注册