Need to get interface info from script

clc2112

Registered
Im writing a getinfo shell script and need to get the number of interfaces and their MAC addresses.

This is what is generated thus far...

CPU: Single 667
DRIVE: 27.94 GB
FirmWare: 4.29f1
CD Type: CD-RW/DVD-ROM
Build: (7D24)
SerNum: QT1527ERLY1
IF Cnt: 2
MAC 1: 00:03:93:5a:ee:42
MAC 2: 00:30:65:1d:87:df
AIRPORT: Yes
Memory: 1 GB

But it really isn't obtained gracefully. I have attempted using the output from the system profiler command (then parsing it) as well as 'ifconfig -a'

if you know of a way to get this info that I can use within a shell script, please let me know.

Thanks!
Calvin
 
Here you go. It ignores the loopback address, and only reports interfaces that are up.

Code:
#!/bin/sh

for x in `ifconfig -lu`; do

        if [ "X$x" != "Xlo0" ]; then
                ether=`ifconfig $x ether | grep ether | awk '{ print $2 }'`
                echo "Interface $x has mac address $ether"
        fi
 
done

Brian
 
Back
Top