Retrieving the MAC address out of a ERA/DRACIII

Michael Weber mweber at alliednational.com
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!

-Michael

#!/bin/sh

address_head="10.1."
let net=1

targ="Target"

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

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

echo "Sort value is $sort_value"

                targ="$address_head$net.$node"
#               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' ]
                then

#                       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 10.1.28.14 -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 ))
                        then

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

                        mysql -h 10.1.28.14 -u arp < sql-command >
sql-output

#                       cat sql-output

                fi

                let node+=1

        done
        let net+=1

done
exit


>>> Michael Halligan <michael.halligan at mypointscorp.com> 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
address
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
mac
addresses to ports and hope that everything is plugged in where the
network
guys say it is.

_______________________________________________
Linux-PowerEdge mailing list
Linux-PowerEdge at dell.com 
http://lists.us.dell.com/mailman/listinfo/linux-poweredge 
Please read the FAQ at http://lists.us.dell.com/faq

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