星期二, 1月 01, 2013

Linux Bash 取 Mac, IP Address 的方法


Linux Bash 裡取 MAC address 的方法:

# 網路找的
ifconfig eth0 | grep HWaddr | tr -s ' ' ' ' | cut -d' ' -f5

# 我的方法
ifconfig eth0 | awk '/HWaddr/ {print $5}'


Linux Bash 設定變數為 IP 值的方法:

ipaddr=$(ifconfig eth0 | awk '/inet addr:/ {print $2}' | awk '{FS=":"} {print $2}')  
# 或是
ifconfig eth0 | awk '/inet addr:/ {print $2}' | tr -d 'addr:'
ifconfig eth0 | awk '/inet addr:/ {print $2}' | sed 's/addr://'


沒有留言: