Created
June 11, 2025 00:55
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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