BASH第七课第一题
来源:互联网 发布:云计算与电子政务 编辑:程序博客网 时间:2024/06/11 04:16
1、写一个脚本getinterface.sh,脚本可以接受参数(i,I,a),完成以下任务:
(1)使用以下形式:getinterface.sh [-i interface|-I IP|-a]
(2)当用户使用-i选项时,显示其指定网卡的IP地址;
(3)当用户使用-I选项时,显示其后面的IP地址所属的网络接口;(如 192.168.199.183:eth0)
(1)使用以下形式:getinterface.sh [-i interface|-I IP|-a]
(2)当用户使用-i选项时,显示其指定网卡的IP地址;
(3)当用户使用-I选项时,显示其后面的IP地址所属的网络接口;(如 192.168.199.183:eth0)
(4)当用户单独使用-a选项时,显示所有网络接口及其IP地址(lo除外)
#!/bin/bashexec 2>>/dev/nullcommand=$1list=`netstat -i | sed -n '3,65535p'|awk -F" " '{print $1}'`[ -z $command ]&&command="-h"function helptext(){echo "getinterface.sh[-i interface|-I IP|-a|-h]"echo "-----------------------------------------" echo "-i interface (show ip of the interface)" echo "-I IP (show interface of the IP)" echo "-a list all interfaces and their IPs"echo "-h show the help text"echo "-----------------------------------------"}if [ $command == "-h" ];thenhelptextelif [ $command == "-i" ];theninterface=$2ifconfig $interface >/dev/nullflag=$?if [ -z $interface ]; thenecho "please input the interface"exit 2elif [ $flag -ne 1 ];thenip=`ifconfig $interface | grep "inet addr" | awk -F" " '{print $2}' | awk -F":" '{print $2}'`echo "$interface $ip"elseecho "$interface is not exist"fielif [ $command == "-I" ];thenIP=$2if [ -z $IP ]; then echo "please input the IP" exit 2elsefor inter in $list;doip_temp=`ifconfig $inter | grep "inet addr" | awk -F" " '{print $2}' | awk -F":" '{print $2}'`if [ $IP == $ip_temp ];thenecho "$IP : $inter"exit 0fidonefiecho "$IP is not exist in the interfaces of the device"elif [ $command == "-a" ];thenfor inter in $list; do ip_temp=`ifconfig $inter | grep "inet addr" | awk -F" " '{print $2}' | awk -F":" '{print $2}'`if [ $inter != "lo" ];thenecho "$inter:$ip_temp"fi doneelseecho "the format error!!!"helptextfi
0 0
- BASH第七课第一题
- BASH第七课第二题
- 第七章第一题
- JAVA第一课第七节知识点
- 第七届蓝桥杯—第一题||煤球数目
- 蓝桥杯-第七届蓝桥杯决赛第一题
- Bash 实例,第一部分
- Bash 实例,第一部分
- 第一个bash脚本
- Bash 实例,第一部分
- Bash 实例,第一部分
- Bash 实例,第一部分
- BASH 实例 第一部分
- 第七周-第一部分
- Linux第一课 命令行BASH的基本操作
- 斯坦福大学IOS开发课程笔记(第七课第一部分)
- 斯坦福大学IOS开发课程笔记(第七课第一部分)
- SQL进阶---第一单元(第七到第十课)、Manipulation
- Jboss提示:Server already running on localhost
- Android实时通讯的基本实现
- HashTable, Dictionary, HashSet的区别
- 压缩跟踪Compressive Tracking源码理解
- 仿微信朋友圈选择图片
- BASH第七课第一题
- A1097. Deduplication on a Linked List (25)
- 控制器操作方法后缀
- Ogre 1.8.1源代码编译和错误修改
- C语言:const关键字、结构体
- BASH第七课第二题
- ZOJ 3781Paint the Grid Reloaded 缩点+bfs
- 压缩跟踪Compressive Tracking
- 《七夕情书项目》