shell 验证ip

#!/bin/bash

function isIp(){
       IP=$1
        if [ `echo $IP | awk -F . ‘{print NF}‘` -ne 4 ];then
                echo "Wrong IP!"
                exit 2
        else
                a=`echo $IP | awk -F . ‘{print $1}‘`
                b=`echo $IP | awk -F . ‘{print $2}‘`
                c=`echo $IP | awk -F . ‘{print $3}‘`
                d=`echo $IP | awk -F . ‘{print $4}‘`
                if [[ $a -gt 0 && $a -le 255 ]] && [[ $b -ge 0 && $b -le 255 ]] && [[ $c -ge 0 && $c -le 255 ]] && [[ $d -gt 0 && $d -lt 255 ]];then
                        #echo "Right IP!"
                        return 0
                        exit
                else
                       # echo "Wrong IP!"
                       return 2
                fi
        fi

}

isIp "192.168.1.902"
时间: 2024-10-14 15:52:19

shell 验证ip的相关文章

javascript正则表达式验证IP,URL

验证IP function isIP(ipstr){ var reg = /^(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])$/g; return ipstr.match(reg); } 这个url的正则验证比较全面,它验证的情况包括IP,域名(domain),ftp,二级域名

[LeetCode] Validate IP Address 验证IP地址

In this problem, your job to write a function to check whether a input string is a valid IPv4 address or IPv6 address or neither. IPv4 addresses are canonically represented in dot-decimal notation, which consists of four decimal numbers, each ranging

Js 正则表达式验证IP地址

1.验证方法 function isValidIP(ip) { var reg = /^(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])$/ return reg.test(ip); } 2.判断 isValidIP(NewIP) == false

[Swift]LeetCode468. 验证IP地址 | Validate IP Address

Write a function to check whether an input string is a valid IPv4 address or IPv6 address or neither. IPv4 addresses are canonically represented in dot-decimal notation, which consists of four decimal numbers, each ranging from 0 to 255, separated by

js验证IP及子网掩码的合法性

function checkIP(ip) {     obj=ip;    var exp=/^(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])$/;     var reg = obj.match(exp);     if(reg==null)     {         re

分享几个ip的方法吧,包括正则验证ip

/// <summary> /// 正规则试验IP地址 /// </summary> /// <param name="IP"></param> /// <returns></returns> public bool IPCheck(string IP) { string num = "(25[0-5]|2[0-4]\\d|[0-1]\\d{2}|[1-9]?\\d)"; return Rege

mac shell 获取ip,自动启动文件http服务

因为工作原因,时常有文件传输需求. rz.nc.rsync都用过,各有各的好处. 但相对的,向别处推文件时总有各种麻烦,尤其是在给同事发送文件时. 然后就想到了提供http服务. 在环境变量中定义别名:alias wser="sh start_HttpServer.sh" wser file_name 把脚本输出语句粘给对方就OK了. 问题解决~ alias wser="sh $ENV_HOME/start_HTTPServer.sh" start_HttpServ

javaScript验证ip的合法性

<script language=javascript> function check(ipaddr) { var ipaddr=document.all.ip.value; var re = /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/; if (re.test(ipaddr)) { //split into units with dots "." var parts = ipaddr.split("."); //if

正则表达式验证ip地址类型格式是否正确

var ipVerification = /^(?:(?:1[0-9][0-9]\.)|(?:2[0-4][0-9]\.)|(?:25[0-5]\.)|(?:[1-9][0-9]\.)|(?:[0-9]\.)){3}(?:(?:1[0-9][0-9])|(?:2[0-4][0-9])|(?:25[0-5])|(?:[1-9][0-9])|(?:[0-9]))$/; if(!ipVerification.test(moduleIP)){ zeroModal.alert('IP地址格式不正确!');