How to Grab MAC Address of Active Ethernet Connection in Bash Script?
        Posted  
        
            by Huy Tran
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by Huy Tran
        
        
        
        Published on 2010-04-21T22:47:55Z
        Indexed on 
            2010/04/21
            22:53 UTC
        
        
        Read the original article
        Hit count: 273
        
bash
Simple Question:
How do I grab the MAC address of the active Ethernet connection in a bash script?
I currently have:
set - `/sbin/ifconfig eth0 | head -1`
MAC=$5
Which outputs the MAC address of the eth0, but if it's eth1 that's active, I want that instead.
Could I beforehand execute ifconfig | grep inet but that wouldn't tell me which interface is active, just that one is active.  I need to grab the line above it to tell me which one is the active connection.
Any help would be much appreciated.
Thank you!
© Stack Overflow or respective owner