1. 程式人生 > >如何取eth0中的IP地址

如何取eth0中的IP地址

方法 很多 掌握即可

以下十多種方法,明白四種即可;

ifconfig eth0 |sed -n ‘2p‘ |sed‘s#^.*addr:##g‘|sed ‘s# B.*$##g‘

ifconfig|awk -F "[: ]+"‘NR==2{print $4}‘

ifconfig |awk NR==2|sed -r‘s#^.*r:(.*)B.*#\1#g‘

ifconfig |sed -rn ‘2s#^.*r:(.*)B.*#\1#gp‘

ifconfig eth0|grep "inet a"|sed -r ‘s#^.*r:(.*)B.*#\1#g‘

ifconfig eth0|sed -rn ‘/inet a/s#^.*r:(.*)B.*#\1#gp‘

ifconfig eth0|grep ‘inetaddr‘|cut -d ":" -f2|cut -d " " -f1

ifconfig eth0|grep ‘inet addr‘|awk -F ":" ‘{print $2}‘|awk ‘{print $1}‘

ifconfig eth0|grep ‘inet addr‘|awk -F ‘[ :]‘ ‘{print $13}‘

ifconfig eth0|sed -n ‘2p‘|awk-F ‘[ :]+‘ ‘{print $4}‘

ifconfig eth0 |awk -F‘[ :]+‘ ‘NR==2 {print $4}‘

ifconfig eth0 |sed

-nr ‘2s#^.*dr:(.*) B.*$#\1#gp

ifconfig eth0|grep -Po ‘(?<=dr:)[0-9.]+‘

ifconfig eth0|sed -nr ‘2s#^.*addr:(.*) Bca.*$#\1#g‘p

ifconfig eth0|sed -n ‘2p‘|sed ‘s#^.*addr:\(.*\)Bc.*$#\1#g‘

hostname -l

如何取eth0中的IP地址