Shell Script 取得 mac address 的方法

本篇記錄 Shell Script 取得 mac address 的方法

shellscript-get-ip.sh
1
2
3
4
#!/bin/bash

MACADDR=`ifconfig eth0 | awk '/HWaddr/ {print $NF}'`
echo "$MACADDR"

執行結果如下,

1
aa:00:11:2b:3c:d4

其它參考
linux - Get MAC address using shell script - Stack Overflow
https://stackoverflow.com/questions/23828413/get-mac-address-using-shell-script
awk - bash script to get MAC address and paste it to ifconfig file after HWADDR - Unix & Linux Stack Exchange
https://unix.stackexchange.com/questions/564175/bash-script-to-get-mac-address-and-paste-it-to-ifconfig-file-after-hwaddr

其它相關文章推薦
Shell Script 新手入門教學
Shell Script 四則運算,變數相加、相減、相乘、相除
Shell Script if 條件判斷
Shell Script while 迴圈
Shell Script 讀檔,讀取 txt 文字檔