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 googline around, I came up with the following solution:

[geshi lang=”bash” nums=”0″ target=”_self” ]

#!/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”


[/geshi]

xx

Leave a Reply

Your email address will not be published.