Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find the hardware type of an interface on iOS and Mac OS X?

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.

like image 250
iKenndac Avatar asked Feb 29 '16 17:02

iKenndac


People also ask

How to enable hardware identification for iOS devices?

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.

How to identify which iOS device I'm on at runtime?

(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.

What are the different types of I/O hardware?

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.

How to view system information in about this Mac?

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.


Video Answer


1 Answers

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
like image 198
eelco Avatar answered Oct 24 '22 13:10

eelco