I'm writing some code that heuristically figures out the likelihood of a service being on a network interface. The hardware I'm searching for doesn't implement SSDP or mDNS, so I have to look for it manually.
The device connects to the network via WiFi, so it's most likely that I'll find it over the WiFi interface. However, it's possible for the Mac to be connected to a WiFi bridge via Ethernet, so it may well be resolvable through that.
To avoid unnecessary requests and to be generally a good network citizen, I'd like to be intelligent about which interface to try first.
I can get the list of interfaces on my computer no problem, but that's not helpful: en0
is wired ethernet on my iMac, but WiFi on my Macbook.
Bonus points if this works on iOS as well, since although it's rare you can use the USB Ethernet adapter with it.
In order to facilitate iOS hardware identification, the following properties should be enabled: screenWidthHeight, audioRef, devicePixelRatio, rendererRef, js.webGlRenderer, js.deviceMotion, deviceAspectRatio You can enable the properties on the Client-side Component download page.
(If you want to distinguish which kind of iOS device you're on at runtime, use the UIDevice class just like you would from ObjC.
Operating System - I/O Hardware. 1 Device Controllers. Device drivers are software modules that can be plugged into an OS to handle a particular device. Operating System takes help from ... 2 Synchronous vs asynchronous I/O. 3 Communication to I/O Devices. 4 Direct Memory Access (DMA) 5 Polling vs Interrupts I/O.
View system information in About This Mac. You can view information about your Mac, including the model name, the macOS version you’re using, and more. To open About This Mac, choose Apple menu > About This Mac. Overview: View the specification information about your Mac.
Use the SystemConfiguration
framework:
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)")
}
}
On my system, this prints:
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With