Not sure if this is helpful to anyone, but as I was tinkering with the same question, I came to this solution:
ifconfig | grep flags=8863 | grep -v bridge
The output will look something like this, and lists only the ethernet ports and wifi that are in active use:
en0: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500
en1: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500
If you'd like to see the assigned IPv4 address as well:
ifconfig | grep 'flags=8863\|inet ' | grep -v 'bridge\|127.0.0.1'
Which produces 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
Another alternative:
scutil --nwi
Which shows the online network devices the last line actually shows the currently active network interfaces:
Network information
IPv4 network interface information
en0 : flags : 0x5 (IPv4,DNS)
address : 192.168.2.147
reach : 0x00000002 (Reachable)
en1 : flags : 0x5 (IPv4,DNS)
address : 192.168.2.244
reach : 0x00000002 (Reachable)
REACH : flags 0x00000002 (Reachable)
IPv6 network interface information
No IPv6 states found
REACH : flags 0x00000000 (Not Reachable)
Network interfaces: en0 en1
Further processing, if needed, is up to you. :-)
Note:
Mind you that I'm not an expert on the flags (8863).
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 */