如何在iOS和Mac OS X上查找接口的硬件类型?

肯达克

我正在编写一些启发式地找出服务在网络接口上的可能性的代码。我要搜索的硬件没有实现SSDP或mDNS,因此我必须手动寻找它。

该设备通过WiFi连接到网络,因此很可能会通过WiFi接口找到它。但是,Mac可以通过以太网连接到WiFi桥接器,因此可以很好地解决。

为了避免不必要的请求并成为一个好的网络公民,我想知道首先尝试使用哪种接口。

我可以毫无问题地获得计算机上的接口列表,但这无济于事:en0iMac上是有线以太网,而Macbook上是WiFi。

如果它也可以在iOS上使用,则要加分,因为尽管很少使用USB以太网适配器。

鳗鱼

使用SystemConfiguration框架:

import Foundation
import SystemConfiguration

for interface in SCNetworkInterfaceCopyAll() as NSArray {
    if let name = SCNetworkInterfaceGetBSDName(interface as! SCNetworkInterface),
       let type = SCNetworkInterfaceGetInterfaceType(interface as! SCNetworkInterface) {
            print("Interface \(name) is of type \(type)")
    }
}

在我的系统上,将打印:

Interface en0 is of type IEEE80211
Interface en3 is of type Ethernet
Interface en1 is of type Ethernet
Interface en2 is of type Ethernet
Interface bridge0 is of type Bridge

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章