不知道这是否对任何人都有用,但是由于我在修改同一个问题,因此我想到了以下解决方案:
ifconfig | grep flags=8863 | grep -v bridge
输出将类似于以下内容,并且仅列出正在使用的以太网端口和wifi:
en0: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500
en1: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500
如果您还想查看分配的IPv4地址:
ifconfig | grep 'flags=8863\|inet ' | grep -v 'bridge\|127.0.0.1'
产生这样的东西;
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
另一种选择:
scutil --nwi
它显示了在线网络设备,最后一行实际上显示了当前活动的网络接口:
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
如果需要,进一步的处理取决于您。:-)
注意:
提醒您,我不是旗帜专家(8863)。您可以在if.h头文件中找到标志的详细信息-Spotlight是您查找“ if.h”的朋友。我在这里找到了我的例子:
/Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk/System/Library/Frameworks/Kernel.framework/Versions/A/Headers/net/if.h
这将向您显示标志的含义(请记住:十六进制);
#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 */
status
具有值active
或inactive
值的字段。