首页 > 系统服务 > 详细

Linux系统下取IP地址的几种方法

时间:2016-03-29 16:41:39      阅读:290      评论:0      收藏:0      [点我收藏+]

Linux系统下取IP地址所在行的方法:
(1)、ifconfig eth0 | grep "inet addr"
          inet addr:10.57.36.112  Bcast:10.57.36.255  Mask:255.255.255.0
注释:grep过滤包含"inet addr"字符串的内容
(2)、ifconfig eth0 | sed -n ‘2p‘
          inet addr:10.57.36.112  Bcast:10.57.36.255  Mask:255.255.255.0
注释:sed -n ‘2p‘其中-n参数表示"取消默认打印",2p表示"打印第2行"
(3)、ifconfig eth0 | sed -n ‘/inet addr/p‘
          inet addr:10.57.36.112  Bcast:10.57.36.255  Mask:255.255.255.0
(4)、ifconfig eth0 | sed -n ‘/Bcast/p‘
          inet addr:10.57.36.112  Bcast:10.57.36.255  Mask:255.255.255.0

Linux系统下取IP地址的几种方法:
(1)、 ifconfig eth0 | grep "inet addr" | awk -F":" ‘{print $2}‘ | awk ‘{print $1}‘
10.57.36.112
(2)、ifconfig eth0 | grep "inet addr"| sed ‘s#^.*addr:##g‘ | sed ‘s#..Bc.*$##g‘
10.57.36.112
(3)、ifconfig eth0 | grep "inet addr"| cut -d: -f2| cut -d" " -f1
10.57.36.112
(4)、ifconfig eth0 | grep "inet addr" | awk -F"[: ]+" ‘{print $4}‘
10.57.36.112
说明:其中取IP地址所在行的方法可采用上述4种方法之一,然后再进行过滤、替换或截取即可获得IP!

本文出自 “Bruce_tan” 博客,请务必保留此出处http://380281.blog.51cto.com/370281/1758063

Linux系统下取IP地址的几种方法

原文:http://380281.blog.51cto.com/370281/1758063

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