说明:这只是个简单的示例。
目前把 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) |