Reputation: 31
How can I use ifconfig to show active interface(s) only and display interface name, MAC address & IP address only. In my scenario, I could have more than one interface.
For example:
eth0 HWaddr 12:34:56:78:90:11 inet addr: 192.168.0.1
Upvotes: 2
Views: 2382
Reputation: 56
I think some manipulation for the output of the ifconfig command using grep, cut will do it.
for example the following line will extract the interfaces with flags UP, RUNNING and BROADCAST , to avoid the loopback and other stuff.. and the interface names are stored in myInterfaces
myInterfaces=`ifconfig | grep -E "UP,BROADCAST,RUNNING" | cut -d : -f 1`
you can then apply a loop over myInterfaces to run the ifconfig separately for each item, and use grep to filter the output to give you just what you need
echo "${myInterfaces}" | while read line || [[ -n $line ]]
do
echo $line $(ifconfig $line | grep -E -o "ether.{0,18}") $(ifconfig $line | grep -E -o "inet .{0,15}"); echo ""
done
for me the output is as follows
enp0s20u1 ether 66:ad:53:93:91:bb inet 192.168.0.133
wlp3s0 ether 80:00:0b:d4:4d:f6 inet 192.168.0.138
Upvotes: 1