#! /bin/bash

checkip() {
        if echo $1 |egrep -q '^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$' ; then
                a=`echo $1 | awk -F. '{print $1}'`
                b=`echo $1 | awk -F. '{print $2}'`
                c=`echo $1 | awk -F. '{print $3}'`
                d=`echo $1 | awk -F. '{print $4}'`

for n in $a $b $c $d; do
                        if [ $n -ge 255 ] || [ $n -le 0 ]; then
                                echo 'bad ip(2)!'
                                return 2
                        fi
                done
        else
                echo 'bad ip(1)!'
                return 1
        fi
}

echo -n "Please input the ip:"
read  ip
checkip  $ip

Shell check IP的更多相关文章

  1. shell 检测ip的合法性与检测网络掩码的合法性

    有时我们需要检测IP输入的正确性与网络掩码的正确性,用shell脚本写的: #验证ip地址的正确性 check_ip_format() { echo $1 | grep "^[0-9]\{1 ...

  2. learning shell check requires root privileges

    [Purpose]        Shell script check requires root privileges   [Eevironment]        Ubuntu 16.04 bas ...

  3. learning shell check host dependent pkg

    [Purpose]        Shell script check host dependent pkg   [Eevironment]        Ubuntu 16.04 bash env ...

  4. shell (check return of each line)and sudoer

    shell result from cmdline echo $? if 0 then success ;else failure (shell 执行每部返回值,rm -rf 错误,打包不能覆盖) 解 ...

  5. shell 验证ip

    #!/bin/bash function isIp(){ IP=$ ];then echo "Wrong IP!" exit else a=`echo $IP | awk -F . ...

  6. 用shell制作IP脚本

    vim  ip.sh #!/bin/bashread -p "eth:" eread -p "ip:" ip1read -p "netmask:&qu ...

  7. Linux shell查询ip归属地

    起因 有的时候写脚本需要能够在脚本中获取到ip的归属地,比如分析登录日志列出攻击者的相关信息等. 可以使用whois来查询ip的详细信息,但是whois并不是每台机器预装的,而且我想看中文的结果,所以 ...

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

    因为工作原因,时常有文件传输需求. rz.nc.rsync都用过,各有各的好处. 但相对的,向别处推文件时总有各种麻烦,尤其是在给同事发送文件时. 然后就想到了提供http服务. 在环境变量中定义别名 ...

  9. shell (check return of each line)(PIPESTATUS[@])and sudoer

    shell result from cmdline echo $? if 0 then success ;else failure (shell 执行每部返回值,rm -rf 错误,打包不能覆盖) 我 ...

随机推荐

  1. 字符串之strstr

    功能:查找第二个字符串是否存在第一个字符串中. 输入:字符串1,字符串2 返回值:成功返回str1中的位置,失败返回NULL #include <iostream> using names ...

  2. boost之算法

    STL里的算法已经很好了,在boost里有几个小的算法 1.BOOST_FOREACH使用方法,定义一个容器里内部类型数据,容器作为参数传递. #include <iostream> #i ...

  3. dataTables的用法

    原地址:http://blog.csdn.net/mickey_miki/article/details/8240477 1.DataTables的默认配置 $(document).ready(fun ...

  4. docker多个容器连接 将 Rails 程序部署到 Docker 容器中

    在docker中使用MySQL数据库 https://yq.aliyun.com/articles/583765 将 Rails 程序部署到 Docker 容器中

  5. pyhton3 re模块

    本文转自 AstralWind 的博客:Python正则表达式指南 特来收藏 1. 正则表达式基础 1.1. 简单介绍 正则表达式并不是Python的一部分.正则表达式是用于处理字符串的强大工具,拥有 ...

  6. 初学JQuery相关知识点

    [简单的JQuery]注册事件的函数. $(document).ready(function(){}) [JQuery提供的函数]$.map(array,fn) 对数组array中每个元素调用fn函数 ...

  7. Python学习进程(2)Python环境的搭建

        本节主要介绍在windows和Linux平台上如何搭建Python编程环境.     (1)查看Python版本: windows: C:\Users\JMSun>python 'pyt ...

  8. 每天一个Linux命令(46)ifconfig命令

    在windows系统中,ipconfig命令行工具被用来获取网络接口配置信息并对此进行修改.Linux系统拥有一个类似的工具,也就是ifconfig(interfaces config).     ( ...

  9. MySQL修改管理员账户密码

    报错提示:ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)MySQL代理报错提示: ...

  10. npm安装出错Unexpected end of input at 1:2307

    执行命令: npm cache clean --force 然后再安装 搞定