写一个脚本checkipadd.sh,判断所输入的参数是否为正确的IP地址,如 果是就输出"This is ip address";如果不是就输出"This is not ip address" (1
来源:互联网 发布:恭亲王奕欣 知乎 编辑:程序博客网 时间:2024/06/06 12:48
写一个脚本checkipadd.sh,判断所输入的参数是否为正确的IP地址,如
果是就输出"This is ip address";如果不是就输出"This is not ip address"
测试如下输入值:
192.168.0.199
95.0.0.1
24.234.2345.1
192.a1.123.0
1a2.1.1.0
01.1.1.1
123
#!/bin/bash
read -p "请输入要检测的IP地址:" input
ip=`echo $input | sed -n '/\./p'`
yi0=`echo $ip |cut -d '.' -f1 `
yi=`echo $yi0 |grep ^0 -v `
if [ $yi -ge 0 -a $yi -lt 256 ] &>/dev/null;then
er0=`echo $ip |cut -d '.' -f2`
sum2=`echo $er0 | wc -c`
[ $sum2 -eq 2 ] && er=`echo $er0 `
[ $sum2 -ge 3 ] && sum2_1=`echo $er0|cut -c1` && [ $sum2_1 -eq 0 ] && echo "This is not ip address" && exit || er=`echo $er0 `
if [ $er -ge 0 -a $er -lt 256 ] &>/dev/null;then
san0=`echo $ip |cut -d '.' -f3`
sum3=`echo $san0 | wc -c`
[ $sum3 -eq 2 ] && san=`echo $san0 `
[ $sum3 -ge 3 ] && sum3_1=`echo $san0|cut -c1` && [ $sum3_1 -eq 0 ] && echo "This is not ip address" && exit || san=`echo $san0 `
if [ $san -ge 0 -a $san -lt 256 ] &>/dev/null;then
si0=`echo $ip |cut -d '.' -f4`
sum4=`echo $si0 | wc -c`
[ $sum4 -eq 2 ] && si=`echo $si0 `
[ $sum4 -ge 3 ] && sum4_1=`echo $si0|cut -c1` && [ $sum4_1 -eq 0 ] && echo "This is not ip address" && exit || si=`echo $si0 `
if [ $si -ge 0 -a $si -lt 256 ] &>/dev/null;then
echo "This is ip address"
else
echo "This is not ip address"
fi
else
echo "This is not ip address"
fi
else
echo "This is not ip address"
fi
else
echo "This is not ip address"
fi
请输入要检测的IP地址:192.168.0.199
This is ip address
请输入要检测的IP地址:95.0.0.1
This is ip address
请输入要检测的IP地址:24.243.2345.1
This is not ip address
请输入要检测的IP地址:192.a1.123.0
This is not ip address
请输入要检测的IP地址:1a2.1.1.0
This is not ip address
请输入要检测的IP地址:01.1.1.1
This is not ip address
请输入要检测的IP地址:123
This is not ip address
阅读全文
0 0
- 写一个脚本checkipadd.sh,判断所输入的参数是否为正确的IP地址,如 果是就输出"This is ip address";如果不是就输出"This is not ip address" (1
- 如何判断一个字符串是否为正确的IP地址
- 判断输入的Ip地址和子网掩码是否正确
- 判断输入的IP格式是否正确
- 判断IP是否正确的shell 脚本
- js判断输入的IP是否合法,IP范围是否正确
- 判断输入的字符串是否为ip地址
- 本地连接服务器的mysql时Host (服务器ip地址) is not allowed to connect to this MySQL server 的解决方法
- 我的 IP 地址(View IP address)
- 传入一个ip地址判读该ip地址是否是正确的ip地址形式
- 判断IP地址是否正确
- 火狐出现 'This address is restricted' 的问题解决办法
- 输入一个整数,判断其是否是2^n,是就输出这个数,不是就输出和它最接近的为2^n的那个整数。
- IP Address控件的使用方法
- IP Address控件的使用方法
- IP address
- ip address
- IP Address
- hbase的架构及设计
- 安卓微信15。。。。。。。。。。。。。。。问题
- 面向对象-this和静态
- Android资源收集(持续更新)
- 在数据库实例中查询v$asm相关视图的问题
- 写一个脚本checkipadd.sh,判断所输入的参数是否为正确的IP地址,如 果是就输出"This is ip address";如果不是就输出"This is not ip address" (1
- html中input(radio,checkbox)取消/选中
- Go语言并发模型:使用 context
- erlang获取离线玩家数据
- javaMail
- 数据库版本化的最佳实践!
- ios 设置状态栏文字颜色为白色
- go语言学习笔记(8) 流程控制
- 文章标题