Get your IP and MAC address from a Linux Shell script
I needed a quick script to get the IP and MAC addresses of some Linux routers from a shell script today.
After a bunch of googling around, I came up with the following solution:
#!/bin/sh
# Get IP and MAC address
IP=(ifconfig 3g-wan | egrep -o ‘([0-9]{1,3}\.){3}[0-9]{1,3}’ | sed -n ‘1p’)
MAC=(ifconfig wlan0 | egrep -o ‘([[:xdigit:]]{2}[:]){5}[[:xdigit:]]{2}’)
echo “IP Address: $IP”
echo “MAC Address: $MAC”