#!/bin/bash
#It ' s written by Caibingsen
#!/bin/bash
#It ' s written by Caibingsen
#date: 2016-03-15
#while设置成死循环, re-enter when the IP entered does not meet the criteria
While:
Do
Read-p "Please enter the IP address to be judged:" IP
#判断输入的ip地址是否仅由数字和点组成, and assigns the value to M.
#判断输入的ip地址的小数点的个数, copy to n
M= ' echo $ip |sed ' s/[0-9. G '
N= ' echo $ip |sed ' s/[0-9]//g ' |wc-c '
#截取ip地址的四个数字的部分, and copy them separately.
N1= ' echo $ip |cut-d '. '-f1 '
N2= ' echo $ip |cut-d '. '-f2 '
N3= ' echo $ip |cut-d '. '-f3 '
N4= ' echo $ip |cut-d '. '-f4 '
#第一个if通过m和n来判断输入的ip是否符合要求
If [-Z $m] && [$n-eq 4] && [-n $n 1] && [-n $n 2] && [-n $n 3] && [-N $n 4 ];then
#第二个if通过n1到n4来判断输入的范围是否符合要求.
If [$n 1-ge 0] && [$n 1-le 255] && [$n 2-ge 0] && [$n 2-le 255] && [$n 3-ge 0] & amp;& [$n 3-le 255] && [$n 4-ge 0] && [$n 4-le 255]
Then
echo "IP Right"
Exit
Else
echo "The IP error you entered, please re-enter"
Fi
Else
echo "The IP error you entered, please re-enter"
Fi
Done
Shell Script--Determine if the IP entered is correct