Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save kichinosukey/c9b8674c79ea5fd4a36581c658428cd4 to your computer and use it in GitHub Desktop.

Select an option

Save kichinosukey/c9b8674c79ea5fd4a36581c658428cd4 to your computer and use it in GitHub Desktop.
Show active network interfaces on macOS and map them to their corresponding Hardware Port names using ifconfig and networksetup.
ifconfig | awk '/^[a-z0-9]+:/{iface=$1} /status: active/{print iface}' | sed 's/://' | while read iface; do
port=$(networksetup -listallhardwareports | awk -v dev="$iface" '
BEGIN {port=""}
/Hardware Port/ {port=$3; for (i=4; i<=NF; i++) port=port " " $i}
/Device/ && $2==dev {print port}
')
echo "$iface : $port"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment