shell篇 — 过滤ip、子网掩码、网关、MC地址

1、查看网卡设备

# ifconfig eth0

eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500

        inet 172.26.211.25  netmask 255.255.240.0  broadcast 172.26.223.255

        ether 00:16:3e:05:e7:df  txqueuelen 1000  (Ethernet)

        RX packets 3304474  bytes 1156152337 (1.0 GiB)

        RX errors 0  dropped 0  overruns 0  frame 0

        TX packets 2714183  bytes 1173508935 (1.0 GiB)

        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

 

2、先行过滤再列截取

# ifconfig eth0 | grep 'inet'

        inet 172.26.211.25  netmask 255.255.240.0  broadcast 172.26.223.255

 

3、-s 删除所有重复出现字符序列,只保留第一个

# ifconfig eth0 | grep 'inet' |tr -s ' '

 

4、执行以上命令后,如果要取

inet  则为ifconfig eth0 | grep 'inet' |tr -s ' ' | cut -d' '  -f2

如果要取 172.26.211.25  则为 ifconfig eth0 | grep 'inet' |tr -s ' ' | cut -d' '  -f3

 

5、过滤ip

# ifconfig eth0 | grep 'inet' |tr -s ' ' | cut -d' '  -f3

172.26.211.25

 

6、过滤子网掩码

#  ifconfig eth0 | grep 'inet' |tr -s ' ' | cut -d' '  -f5

 

7、过滤子网掩码、IP、网关

# ifconfig eth0 |grep 'inet' |tr -d 'a-zA-Z:' |tr ' ' '\n' |grep -v '^$'

 

8、过滤inet的行,去掉大小字符和冒号,对空格替换成回车符号

# ifconfig eth0 |grep 'inet' |tr -d 'a-zA-Z:' |tr ' ' '\n'

 

9、过滤inet的行,去掉大小字符和冒号

# ifconfig eth0 |grep 'inet' |tr -d 'a-zA-Z:'

 

10、过滤inet的行

# ifconfig eth0 |grep 'inet'

 

11、过滤MC地址【过滤ether行,压缩空格,以空格为分隔符,取第3列】

# ifconfig eth0 |grep 'ether'|tr -s ' ' |cut -d' ' -f3

00:16:3e:05:e7:df

 

12、过滤ether行,压缩空格

# ifconfig eth0 |grep 'ether'|tr -s ' '

 

声明:以上纯属博主学习历程笔记,依靠参考及其理解实战编写而成,后期会持续更新!

参考

https://www.bilibili.com/video/BV1st411N7WS?p=7

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值