Mac OSX Terminal – Get Active Interface

| | | |

This will let you know which network interface you are actively using should you have Wi-Fi and Ethernet connected.

route get default | grep interface | awk '{print $2}'

Get name of network interface

ActiveNetwork=$(route get default | grep interface | awk '{print $2}')
ActiveNetworkName=$(networksetup -listallhardwareports | grep -B 1 "$ActiveNetwork" | awk '/Hardware Port/{ print }'|cut -d " " -f3-)
echo $ActiveNetwork
echo $ActiveNetworkName

Originally Posted on June 23, 2016
Last Updated on March 6, 2017
All information on this site is shared with the intention to help. Before any source code or program is ran on a production (non-development) system it is suggested you test it and fully understand what it is doing not just what it appears it is doing. I accept no responsibility for any damage you may do with this code.