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

前端 未结 19 1879
面向向阳花
面向向阳花 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:11

    I prefer the method described here (with slight modification): http://www.askdavetaylor.com/how_do_i_figure_out_my_ip_address_on_a_mac.html

    ifconfig | grep "inet " | grep -v 127.0.0.1 | cut -d " " -f2
    

    Which you can then alias to a short 'myip' command for future use:

    echo "alias myip=\"ifconfig | grep 'inet ' | grep -v 127.0.0.1 | cut -d ' ' -f2\"" >> ~/.bash_profile
    

提交回复
热议问题