# Get mac address for "ifconfig -a" command
# The output of "ifconfig -a" is as follows (note that either eth0 or tr0 would be UP, not both ???)
#
# Command example
#     awk -fget_macaddr_awk input-file-name  >  output-file-name
#
#   eth0      Link encap:Ethernet  HWaddr 00:60:94:EB:16:5E  
#             inet addr:9.3.154.26  Bcast:9.3.154.31  Mask:255.255.255.224
#             UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
#             ...
#   lo        Link encap:Local Loopback  
#             inet addr:127.0.0.1  Mask:255.0.0.0
#             UP LOOPBACK RUNNING  MTU:3924  Metric:1
#             ...
# 
#  tr0       Link encap:16/4 Mbps Token Ring  HWaddr 00:20:35:5F:15:94  
#            inet addr:9.53.113.245  Bcast:9.53.113.255  Mask:255.255.254.0
#            UP BROADCAST RUNNING MULTICAST  MTU:2000  Metric:1
#             ...
#
#

BEGIN {
   eth0_line = 200; 
}

{
       # check for eth0 line
	if ($1 == "eth0") {
	    eth0_mac = $5;
            eth0_line = NR;
#            printf("Debug: eth0_mac=%s, line #  %s\n", $5,  eth0_line); 
       }    # end if statement
       # check for tr0 line
	if ($1 == "tr0") {
	    tr0_mac = $8;
            tr0_line = NR;
#            printf("Debug: tr0_mac=%s, line #  %s\n", $5,  tr0_line); 
       }    # end if statement
       # if eth0 is UP (2 lines below eth0 line), it contains the real mac address
       if ((NR == (eth0_line + 2)) &&  ($1 == "UP")) {
            printf("mac=%s\n", eth0_mac );
       }    # end if statement
       # if tr0 is UP (2 lines below eth0 line), it contains the real mac address
       if ((NR == (tr0_line + 2)) &&  ($1 == "UP")) {
            printf("mac=%s\n", tr0_mac );
       }    # end if statement

}

END { }
