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

前端之家收集整理的这篇文章主要介绍了如何在iOS和Mac OS X上找到接口的硬件类型?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
@H_502_4@
我正在编写一些代码,启发式地计算出服务在网络接口上的可能性.我正在搜索的硬件没有实现SSDP或mDNS,所以我必须手动查找.

该设备通过WiFi连接到网络,因此我很可能通过WiFi接口找到它.但是,Mac可以通过以太网连接到WiFi网桥,因此可以通过它进行解析.

为了避免不必要的请求并且通常是一个好的网络公民,我想知道首先尝试哪个界面.

我可以在我的计算机上获得接口列表没问题,但这没有用:en0是我的iMac上的有线以太网,但我的Macbook上有WiFi.

如果这也适用于iOS,则奖励积分,因为虽然很少有人可以使用USB以太网适配器.

@H_502_4@

解决方法

使用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
@H_502_4@ @H_502_4@

猜你在找的cocoa相关文章