macos – How to find the currently connected network service from the command line?

Dhanisa Mashilfa

Not certain if this is helpful to any individual, but as I was tinkering with the identical dilemma, I came to this answer:

ifconfig | grep flags=8863 | grep -v bridge

The output will glimpse something like this, and lists only the ethernet ports and wifi that are in lively use:

en0: flags=8863 mtu 1500
en1: flags=8863 mtu 1500

If you would like to see the assigned IPv4 handle as nicely:

ifconfig | grep 'flags=8863|inet ' | grep -v 'bridge|127...1'

Which produces something like this

en0: flags=8863 mtu 1500
    inet 192.168.2.147 netmask 0xffffff00 broadcast 192.168.2.255
en1: flags=8863 mtu 1500
    inet 192.168.2.244 netmask 0xffffff00 broadcast 192.168.2.255

Another alternative:

scutil --nwi

Which demonstrates the on line community units the previous line actually demonstrates the at the moment active network interfaces:

Community information

IPv4 network interface information and facts
     en0 : flags      : 0x5 (IPv4,DNS)
           deal with    : 192.168.2.147
           get to      : 0x00000002 (Reachable)
     en1 : flags      : 0x5 (IPv4,DNS)
           tackle    : 192.168.2.244
           access      : 0x00000002 (Reachable)

   Arrive at : flags 0x00000002 (Reachable)

IPv6 network interface info
   No IPv6 states discovered


   Get to : flags 0x00000000 (Not Reachable)

Network interfaces: en0 en1

Even more processing, if required, is up to you. 🙂


Be aware:

Brain you that I am not an skilled on the flags (8863).
You can discover the flag particulars in the if.h header file – Spotlight is your friend in discovering “if.h”. I found mine for instance here:

/Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk/Technique/Library/Frameworks/Kernel.framework/Versions/A/Headers/internet/if.h

which will present you what the flags indicate (maintain in brain: hexadecimal)

#define IFF_UP          0x1             /* interface is up */
#outline IFF_BROADCAST   0x2             /* broadcast address legitimate */
#define IFF_DEBUG       0x4             /* flip on debugging */
#define IFF_LOOPBACK    0x8             /* is a loopback net */
#define IFF_POINTOPOINT 0x10            /* interface is issue-to-stage link */
#outline IFF_NOTRAILERS  0x20            /* out of date: steer clear of use of trailers */
#define IFF_Working     0x40            /* assets allocated */
#define IFF_NOARP       0x80            /* no address resolution protocol */
#outline IFF_PROMISC     0x100           /* obtain all packets */
#outline IFF_ALLMULTI    0x200           /* obtain all multicast packets */
#outline IFF_OACTIVE     0x400           /* transmission in progress */
#determine IFF_SIMPLEX     0x800           /* can't listen to individual transmissions */
#define IFF_LINK0       0x1000          /* per connection layer outlined little bit */
#outline IFF_Website link1       0x2000          /* for every connection layer described bit */
#outline IFF_Backlink2       0x4000          /* for every hyperlink layer outlined bit */
#determine IFF_ALTPHYS     IFF_Link2       /* use alternate actual physical relationship */
#determine IFF_MULTICAST   0x8000          /* supports multicast */

Next Post

Halloween Sale 2021 Discount Codes

Halloween is near, so gather with all your friends and family to cherish these early moments with the activities and traditions we follow every year. Get ready with your costumes and favorite horror movies you saved to watch them on a perfect occasion. Let’s celebrate this holiday by warding off the […]
Halloween Sale 2021 Discount Codes