I Am Bot

Srinath on Web development, technology and other titbits

MAC/IP Address Using Linux Shell Script

Ever wanted to get the MAC/IP address of your computer in a Linux shell script? The following two commands should work on most flavours of Linux/Unix

Note: It retrieves the address of eth0 interface by default. Make necessary changes as required.

IP:

/sbin/ifconfig | grep ‘\<inet\>’ | sed -n ‘1p’ | tr -s ” ” | cut -d ” ” -f3 | cut -d “:” -f2

MAC (H/W address)

/sbin/ifconfig | grep ‘eth0’ | tr -s ” ” | cut -d ” ” -f5

Comments