This article mainly introduced the shell regular expression authentication IP address, this article has given several methods, and gives the realization code separately, needs the friend to be possible to refer to under
Multiple IP on this machine
The code is as follows:
Ifconfig | awk '/inet/{print $} ' | Awk-f: ' {print $} '
First, use this first.
The code is as follows:
Checkipaddress ()
{
echo $ >/tmp/tmpserverip
echo $ |grep "^[0-9]{1,3}. [0-9] {1,3}. [0-9] {1,3}. [0-9] {1,3}$ ">/dev/null
If [$? = 1]; Then
Return 1
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)
For the loop in $a $b $c $d
Todo
If [$loop-ge 255] | | [$loop-le 0]; Then
Return 2
Fi
Done
Fi
return 0
}
At first, refer to the following
The code is as follows:
grep "^" ([01]?dd?| 2[0-4]D|25[0-5]). ([01]?dd?| 2[0-4]D|25[0-5]). ([01]?dd?| 2[0-4]D|25[0-5]). ([01]?dd?| 2[0-4]D|25[0-5]). $ "
Input IP, check whether it is satisfied with the IP writing specification, that is, can not be greater than 255, can not have letters, and other punctuation, refer to the Internet, they made a following, make a mark!@
The code is as follows:
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
}