Chinaunix首页 | 论坛 | 博客
  • 博客访问: 350281
  • 博文数量: 60
  • 博客积分: 1570
  • 博客等级: 上尉
  • 技术积分: 620
  • 用 户 组: 普通用户
  • 注册时间: 2009-11-02 23:37
文章分类

全部博文(60)

文章存档

2012年(2)

2010年(2)

2009年(56)

分类: LINUX

2009-12-05 13:12:23

 

说明:这只是个简单的示例。

目前把 0.0.0.0 和 255.255.255.255 视为合法的IP地址。

 

#!/bin/sh

function checkip {
        dot=`echo $1 | awk -F '.' '{print NF-1}'`
        if [ $dot -ne 3 ]; then
                return 1
        fi

        count=0
        for var in `echo $1 | awk -F. '{print $1, $2, $3, $4}'`
        do
                echo $var | grep "^[0-9]*$" >/dev/null
                if [ $? -ne 0 ]; then
                        return 1
                fi

                if [ $var -ge 0 -a $var -le 255 ] ; then
                        ((count=count+1))
                        continue
                else
                        return 1
                fi
        done

        if [ $count -eq 4 ]; then
                return 0
        else
                return 1
        fi
}

while true; do
        echo -n "************** Please Enter Management Center IP:"
        read IP
        checkip ${IP}
        case $? in
                0)
                        break
                        ;;
                1)
                        echo "Your input ${IP} is invalid."
                        ;;
        esac
done

        echo "valid ip=${IP}"


阅读(2696) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~