WWDC2019 的“网络进步”演讲中有这个NWEthernetChannel
用于监控自定义(非 IP)协议的示例。这是针对 MacOS 的。
import Foundation
import Network
let path = NWPathMonitor(requiredInterfaceType: .wiredEthernet).currentPath
guard let interface = path.availableInterfaces.first else {
fatalError("not connected to Internet")
}
let channel = NWEthernetChannel(on: interface, etherType: 0xB26E)
对于我的应用程序,我需要使用 aNWEthernetChannel
来监控没有 IP Internet 连接(但它确实有到交换机的物理链路)的以太网链路上的自定义协议(实际上是 Cisco 发现协议和/或链路层发现协议)。如果 NWPath 是通往 Internet 的有效路径,NWPath 似乎只会给我一个 NWInterface 结构。
如何NWInterface
在没有有效 Internet 路径的情况下获取 Mac 上的结构列表?
在我的特定用例中,我只对.wiredEthernet.
像NWInterfaces
在一个盒子上得到一个完整的数组这样简单的东西就足够了,但到目前为止,NWInterfaces
我发现“出售”的唯一方法是 with NWPathMonitor
,这似乎需要 IP 连接。