ip的合法性判断

xiaoxiao2021-02-27  161

#!/bin/bash #2017830日 #by lee #auto test the ip IP_ADDR=$1 IP_DIR="ip.txt" test_ipA(){ if [[ $1 -gt 254 ]] || [[ $1 -le 0 ]];then echo "the ip is illegal" exit 0 fi } test_ipB(){ if [[ $1 -gt 254 ]] || [[ $1 -lt 0 ]];then echo "the ip is illegal" exit 0 fi } echo $IP_ADDR > $IP_DIR grep --color -E "([0-9]{1,3}.){3}[0-9]{1,3}" $IP_DIR > /dev/null if [[ $? -ne 0 ]];then echo "the ip is illegal" exit 0 else a=`awk -F "." '{print $1}' ${IP_DIR}` #传递参数给函数 test_ipA "$a" b=`awk -F "." '{print $2}' ${IP_DIR}` test_ipB $b c=`awk -F "." '{print $3}' ${IP_DIR}` test_ipB $c d=`awk -F "." '{print $4}' ${IP_DIR}` test_ipA $d echo "the ip is legal" fi
转载请注明原文地址: https://www.6miu.com/read-16990.html

最新回复(0)