首页 > 试题

addr

更新时间:2022-12-11 02:00:34 阅读: 评论:0

本科小学教育要学高数吗-英语单词造句


2022年12月11日发(作者:英语日常交际用语)

如何获取ip地址

1、

[root@centos6~]#ifconfigeth0|grep'inetaddr:'###过滤不是IP地址的⾏

inetaddr:192.168.16.100Bcast:192.168.16.255Mask:255.255.255.0

或者

[root@centos6~]#ifconfigeth0|d-n'2p'###过滤不是IP地址的⾏

inetaddr:192.168.16.100Bcast:192.168.16.255Mask:255.255.255.0

[root@centos6~]#ifconfigeth0|d-n'2p'|d-n's#^.*dr:##gp'

192.168.16.100Bcast:192.168.16.255Mask:255.255.255.0###已经去掉IP地址头部了。

[root@centos6~]#ifconfigeth0|d-n'2p'|d-n's#^.*dr:##gp'|d-n's#B.*$##gp'

###去掉IP地址尾巴。

192.168.16.100

2、⽤grep或d&&cut组合提取

[root@centos6~]#ifconfigeth0|grep"inetaddr:"|cut-d":"-f2|cut-d""-f1

[root@centos6~]#ifconfigeth0|grep"inetaddr:"|cut-f2-d":"|cut-f1-d""

[root@centos6~]#ifconfigeth0|grep"inetaddr:"|cut-d:-f2|cut-d""-f1

[root@centos6~]#ifconfigeth0|d-n'2p'|cut-c21-35

cut截取命令,-d""⽤引号内符号分割,-fnn代表分割之后的区域

3、⽤grep或d&&awk来提取

[root@centos6~]#ifconfigeth0|grep"inetaddr"|awk-F'[:]+''{print$4}'

[root@centos6~]#ifconfigeth0|d-n'/inetaddr/p'|awk-F'[:]+''{print$4}'

4、直接⽤d正则表达式来匹配

[root@centos6~]#ifconfigeth0|d-rn's#^.*dr:(.*)B.*$#1#gp'

[root@centos6~]#ifconfigeth0|d-n's#^.*dr:.∗B.*$#1#gp'

5、直接⽤awk正则表达式来匹配

[root@centos6~]#ifconfigeth0|awk-F'[:]+''NR==2{print$4}'

[root@centos6~]#ifconfigeth0|awk-F'[:]+''/Bcast/{print$4}'

[root@centos6~]#ifconfigeth0|awk-F'[:]+''/inetaddr:/{print$4}'

[root@centos6~]#ifconfigeth0|awk-F'[:]+''$0~"inetaddr"{print$4}'

6、直接⽤grep正则表达式来匹配IP地址数字

[root@centos6]#ifconfigeth0|grep-o"[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.[0-46-9]{3}"

或者下⾯精简的⽅法:

[root@centos7]#ifconfigeth0|grep-Eo'([0-9]+[.]){3}[0-9]+'|grep-v"255"

10.0.0.61

ifconfigeth0|grep-Po'(?<=inet)[0-9.]+'#centos7#(centos7)

10.0.0.31

ifconfigeth0|grep-Po'(?<=addr:)[0-9.]+'#(centos6)

ifconfigeth0|egrep-o"([0-9]{1,3}.){3}[0-9]{1,3}"|grep-wv255

#第⼀次优化后

ifconfigeth0|grep-Eo'([0-9]+.){3}([0-9]+)'|grep-wv"255"

#第⼆次优化后

ifconfigeth0|grep-Po'[0-9.]+(?=netmask)'#centos7(两个空格)

ifconfigeth0|grep-Po'(?<=inet)[0-9.]+'#centos7

ifconfigeth0|grep-Po'[0-9.]+(?=Bcast)'#centos6(两个空格)

ifconfigeth0|grep-Po'(d{1,3}W){3}d{1,3}'|grep-v"255"

#第三次优化后

ifconfigeth0|grep-Po"[d.]+(?=netmask)"#centos7(两个空格)

ifconfigeth0|grep-Po"[d.]+(?=Bcast)"#centos6(两个空格)

7、

[root@centos6~]#ipaddr|grep-Po'[^]+(?=/d)'|d-n'3p'

[root@centos6~]#ifconfigeth0|d-n'2p'|grep-Pio'[^:a-z]+'|d-n1p

8、直接提取IP地址⽂件。

/etc/sysconfig/network-scripts/ifcfg-eth0

[root@centos6~]#cat/etc/sysconfig/network-scripts/ifcfg-eth0|d-n'10p'|cut-d"="-f2

9、

hostname-I|awk'{print$1}'

10、获取的是公⽹IP

11、

iproute|awk'NR==1{print$NF}'

iproute|awk'NR<2{print$NF}'

12、mac端复制拷贝ip

ifconfigen0|grep-o"[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.[0-46-9]{3}"|pbcopy

本文发布于:2022-12-11 02:00:34,感谢您对本站的认可!

本文链接:http://www.wtabcd.cn/fanwen/fan/88/82762.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

上一篇:rmax
下一篇:allegation
标签:addr
相关文章
留言与评论(共有 0 条评论)
   
验证码:
推荐文章
排行榜
Copyright ©2019-2022 Comsenz Inc.Powered by © 专利检索| 网站地图