从默认接口获取mac地址

・1 分钟阅读


 $ netstat -rn | awk '/default/ { print $NF }' | head -1 | xargs -I {} ifconfig {} | awk '/ether/ {print $2}'

说明

netstat -rn - > get routing table awk'/default/{ print $NF }'- > grep the default routes head -1 - > limit to the first result (is also the interface with the highest priority xargs -I {} ifconfig {} - > use the result to get data from ifconfig awk'/ether/{print $2}'- > grep the mac address .

限制

在OSX上测试过。

Hujiuxiang profile image