Retrieving the MAC address out of a ERA/DRACIII

Michael Weber mweber at
Fri Mar 4 16:02:01 CST 2005

Here is a hunk of code I am writing to keep track of all the MAC's in my
network using a MySQL database.

The guts of it is the ping command followed by the arp command.  If you
know the IP's, you can pretty easily cut and paste pieces of my script
into something that will give you what you need, either in a
pre-formatted dhcp.conf style, or whatever you need.

Note:  I am a sysadmin, not a coder.  It works, but may not be the most
efficient piece of coding you have ever seen.

Hope it helps!



let net=1


while (( $net<255 ))
        let node=1
        while (( $node<255 ))

                let sort_value=($net*1000)+$node

echo "Sort value is $sort_value"

#               echo "Target is $targ"
                ping -q -c 1 -w 1 $targ > /dev/null
                # Pull the address from the arp cache
                targ_mac=${arp -na $targ | awk '{print $4}' }

#               echo "if [ '$targ_mac' != '<incomplete>' ]"
                if [ $targ_mac != '<incomplete>' -a $targ_mac !=
'entries' ]

#                       echo "MAC address for $targ is $targ_mac"

                        echo "use arp;" > sql-command
                        echo "select * from hosts where MAC_Address =
\"$targ_mac\";" >> sql-command

                        mysql -h -u arp < sql-command | grep
"10.1." | awk '{print $2}' > sql-output

                        echo "use arp;" > sql-command

                        targ_name=`host $targ | head -1 | awk {'print
$5'} | grep -v NXDOMAIN | awk -F. {'print $1'}`
                        if (( `cat sql-output | wc -c` > 5 ))

                                echo "UPDATE hosts SET IP_ADDRESS =
\"$targ\", host_name = \"$targ_name\" WHERE MAC_Address =
\"$targ_mac\";" >> sql-command
                                echo "INSERT INTO hosts (IP_Address,
MAC_Address, sort_by, host_name) VALUES
(\"$targ\",\"$targ_mac\",\"$sort_value\",\"$targ_name\");" >>

                        mysql -h -u arp < sql-command >

#                       cat sql-output


                let node+=1

        let net+=1


>>> Michael Halligan <michael.halligan at> 03/04 3:15 PM
This has been posted once before, but never received a solution.

How do you find the mac address for a rac card? I need to find the
on about 200 machines, since I'm moving all of my rac from static
configs to
dhcp, and I'd really rather not have to log into my switches to map
addresses to ports and hope that everything is plugged in where the
guys say it is.

Linux-PowerEdge mailing list
Linux-PowerEdge at 
Please read the FAQ at

CONFIDENTIALITY NOTICE:  This communication and any 
attached or enclosed files may contain information 
that is privileged, confidential, proprietary and/or 
otherwise protected from disclosure under applicable 
law ("Confidential Information").  Any review, 
retransmission, publication, dissemination, 
distribution, forwarding, printing, copying, storing, saving 
or other use or disclosure of this communication and/or the 
Confidential Information, or taking any action in reliance 
thereon, by an individual or entity other than the intended 
recipient(s) is strictly prohibited.  

This communication and the Confidential Information are 
intended solely for the use of the individual(s) and/or 
entity(ies) to which this communication is addressed. 
If you are not the intended recipient(s) (or responsible 
for delivery to said recipient(s)), please be advised 
that you have received this communication in error and 
have an obligation to promptly inform the sender by reply 
e-mail or facsimile and to permanently delete, shred or 
otherwise destroy, in its entirety, this original communication 
and all copies thereof, whether in electronic or hard copy format. 

More information about the Linux-PowerEdge mailing list