Shell獲取IP地址的多種方法

 ifconfig eth0|grep -Po "(?<=addr:).*(?=Bcast)"

 ifconfig eth0|sed -n 's/.*addr://;s/Bcast.*//p'

 ifconfig | awk -F"[: ]" 'NR==2 {print $13}'

 ifconfig eth0|sed -rn 's/.*:(.*)  B.*/\1/p'     注意B前面有個空格

 ifconfig eth0 |awk -F '[ :]+' '/inet addr/{print $4}'


感謝各位羣友的總結!


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章