首页 > 其他 > 详细

显示所有网卡IP地址

时间:2015-02-01 17:25:00      阅读:252      评论:0      收藏:0      [点我收藏+]

#!/bin/bash
#function:display all interface ip address
inter_num=`ifconfig|grep ^eth|wc -l` #统计有几块网卡
num=$((inter_num - 1)) #因为网卡接口从0开始,减一个1
for i in `seq 0 $num` #因为网卡接口从0开始,所以取从0开始的数字序列
do
inter_ip=`ifconfig|grep -A 1 eth$i|tail -1|cut -d ":" -f 2|cut -d " " -f1`
inter_mask=`ifconfig|grep -A 1 eth$i|tail -1|cut -d":" -f 4`
echo "eth$i ip address is $inter_ip"
echo "eth$i ip address mask is $inter_mask"
done
========================================


cut
-d 自定义分隔符,例如 cut -d “:”
-f 与-d配合使用,作用指定需要截取哪个区域,例如 cut -d ":" -f 1


新式运算方法:
inter_num=5
num=$((inter_num - 1))
echo $num

显示所有网卡IP地址

原文:http://www.cnblogs.com/blog-acf/p/4265680.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!