private static func getEthernetIPAddress(from interfaces: [String: String]) -> String? { // 常见虚拟以太网接口名(根据适配器型号可能不同) let poeEthernetInterfaces = ["en2", "en3", "en4", "en5", "eth0", "eth1"]
for interfaceName in poeEthernetInterfaces {
if let ethernetIP = interfaces[interfaceName], !ethernetIP.isEmpty {
return ethernetIP
}
}
return nil
}//我们通过该方法去抓取有线网的IP地址,但是有的设备无法抓取到,怎样才能更准确的抓取到有线网络的IP地址
Sadly, I can’t read Chinese, so I’m answering based on a machine translation.
The code you posted assumes that a specific interface type will have a specific interface name. That’s not a valid assumption. BSD interface names are not considered API on Apple platforms.
I have a lot more information about this in the various posts referenced by Extra-ordinary Networking. Please read them through. If you have follow-up questions, I’d be happy to answer them here.
Share and Enjoy
—
Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"