Shell Regular expression authentication IP address _linux shell

Source: Internet
Author: User
Tags echo b echo d

Multiple IP on this machine

Copy Code code as follows:

Ifconfig | awk '/inet/{print $} ' | Awk-f: ' {print $} '

First, use this first.

Copy Code code 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

Copy Code code as follows:

grep "^" ([01]?\d\d?| 2[0-4]\D|25[0-5]) \. ([01]?\d\d?| 2[0-4]\D|25[0-5]) \. ([01]?\d\d?| 2[0-4]\D|25[0-5]) \. ([01]?\d\d?| 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, reference on the Internet, they made a following, make a mark! @

Copy Code code 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
}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.