Shell finishing (31) = = = To determine if the input is IP

Source: Internet
Author: User

(title): Determine if the incoming parameter is IP


Idea: 192.168.1.1

is the condition of the IP, * * * dot decimal This four number must be less than 255

Dot decimal must be guaranteed to be a number, not a letter

#!/bin/bash[ -z $1 ] && echo  "uesage :  ' basename $0 '  ip " && exit 0check  ()  {         A= ' echo $1 | awk -f.  ' {if ($1<255 && $2<255 &&  $3<255 && $4<255) {print  "yes"} '          if echo $1|egrep  "^[0-9]{1,3}\. [0-9] {1,3}\. [0-9] {1,3}\. [0-9] {1,3}$ ">/dev/null        then             if [  $a  ==  "yes"  ]; then                 echo  "Yes"              else                 echo&nBSP; " No "           fi         else                 echo  "No"         fi}check $1


This article is from the "It Life" blog, so be sure to keep this source http://dingxue.blog.51cto.com/12290895/1973946

Shell finishing (31) = = = To determine if the input is IP

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.