Best way to extract MAC address from ifconfig's output?

前端 未结 19 1873
面向向阳花
面向向阳花 2020-12-12 15:31

What is the best way to extract the MAC address from ifconfig\'s output?

Sample output:

bash-3.00# ifconfig eth0        
eth0      Link          


        
19条回答
  •  无人及你
    2020-12-12 16:27

    I needed to get MAC address of the active adapter, so ended up using this command.

    ifconfig -a | awk '/^[a-z]/ { iface=$1; mac=$NF; next } /inet addr:/ { print mac }' | grep -o -E '([[:xdigit:]]{1,2}:){5}[[:xdigit:]]{1,2}'
    

    Hope it helps.

提交回复
热议问题