I had to figure a way to see what ethernet or wifi ports were actively connected.
Here 'ifconfig' could have been great but it provides a LOT of data. So here a one-liner for Terminal to see the active connections:
ifconfig | grep flags=8863 | grep -v bridge
The output will look something like this:
en0: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500
en1: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500
Here we see en0 and en1 being active (my Ethernet ports), or for example
en0: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500
en1: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500
en2: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500
where en2 is my WiFi.
If you'd like to see the IPv4 address as well, then try this:
ifconfig | grep 'flags=8863\|inet ' | grep -v 'bridge\|127.0.0.1'
Which will list something like this:
en0: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500
inet 192.168.2.147 netmask 0xffffff00 broadcast 192.168.2.255
en1: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500
inet 192.168.2.244 netmask 0xffffff00 broadcast 192.168.2.255
en2: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500
inet 192.168.2.245 netmask 0xffffff00 broadcast 192.168.2.255
Here you see only the active network connections (Ethernet and WiFi) and the IPv4 IP address.
Note: I'm no expect on the flags. You can find the flag details in the **if.h** header file - Spotlight is your friend in finding "if.h". I found mine for example here:
/Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk/System/Library/Frameworks/Kernel.framework/Versions/A/Headers/net/if.h
which will show you what the flags mean (keep in mind: hexadecimal);
#define IFF_UP 0x1 /* interface is up */
#define IFF_BROADCAST 0x2 /* broadcast address valid */
#define IFF_DEBUG 0x4 /* turn on debugging */
#define IFF_LOOPBACK 0x8 /* is a loopback net */
#define IFF_POINTOPOINT 0x10 /* interface is point-to-point link */
#define IFF_NOTRAILERS 0x20 /* obsolete: avoid use of trailers */
#define IFF_RUNNING 0x40 /* resources allocated */
#define IFF_NOARP 0x80 /* no address resolution protocol */
#define IFF_PROMISC 0x100 /* receive all packets */
#define IFF_ALLMULTI 0x200 /* receive all multicast packets */
#define IFF_OACTIVE 0x400 /* transmission in progress */
#define IFF_SIMPLEX 0x800 /* can't hear own transmissions */
#define IFF_LINK0 0x1000 /* per link layer defined bit */
#define IFF_LINK1 0x2000 /* per link layer defined bit */
#define IFF_LINK2 0x4000 /* per link layer defined bit */
#define IFF_ALTPHYS IFF_LINK2 /* use alternate physical connection */
#define IFF_MULTICAST 0x8000 /* supports multicast */
So 8863 means;
MULTICAST (0x8000) + SIMPLEX (0x800) + RUNNING (0x40) + NOTRAILERS (0x20) + BROADCAST (0x2) + UP (0x1).
Interested in know what en0, en1, etc stands for?
Try this:
networksetup -listnetworkserviceorder
Example output:
An asterisk (*) denotes that a network service is disabled.
(1) Ethernet 1
(Hardware Port: Ethernet 1, Device: en0)
(2) Ethernet 2
(Hardware Port: Ethernet 2, Device: en1)
(3) Wi-Fi
(Hardware Port: Wi-Fi, Device: en2)
(4) Bluetooth PAN
(Hardware Port: Bluetooth PAN, Device: en9)
(5) Thunderbolt Bridge
(Hardware Port: Thunderbolt Bridge, Device: bridge0)