文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>shell输入 ip 合法性

shell输入 ip 合法性

时间:2007-10-14  来源:zhangzhu1984

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

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
         }

相关阅读 更多 +
排行榜 更多 +
辰域智控app

辰域智控app

系统工具 下载
网医联盟app

网医联盟app

运动健身 下载
汇丰汇选App

汇丰汇选App

金融理财 下载