Created
August 12, 2025 00:09
-
-
Save thecrypticace/73fffaa693ba748b95c3b2a4ab4c577e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import Cocoa | |
| import IOKit | |
| func coreDeviceInterfaces() -> [String] { | |
| var iterator = io_iterator_t() | |
| let masterPort: mach_port_t = kIOMainPortDefault | |
| let matchingDict: CFDictionary = IOServiceMatching("IONetworkInterface") | |
| var kernResult: kern_return_t | |
| var name: [CChar] = Array(repeating: 0, count: 256) | |
| var path: [CChar] = Array(repeating: 0, count: 2048) | |
| kernResult = IOServiceGetMatchingServices(masterPort, matchingDict, &iterator) | |
| guard kernResult == KERN_SUCCESS else { return [] } | |
| defer { IOObjectRelease(iterator) } | |
| var interfaces: [String] = [] | |
| while true { | |
| let object = IOIteratorNext(iterator) | |
| guard object != 0 else { break } | |
| defer { IOObjectRelease(object) } | |
| kernResult = IORegistryEntryGetPath(object, "IOService", &path) | |
| guard kernResult == KERN_SUCCESS else { continue } | |
| kernResult = IORegistryEntryGetName(object, &name) | |
| guard kernResult == KERN_SUCCESS else { continue } | |
| guard | |
| let name = String(cString: name, encoding: .ascii), | |
| let path = String(cString: path, encoding: .ascii) | |
| else { | |
| continue | |
| } | |
| // A better check would be for a AppleUSBNCMData parent or IOUSBHostDevice parent | |
| guard path.contains("iPhone") else { continue } | |
| interfaces.append(name) | |
| } | |
| return interfaces | |
| } | |
| print(coreDeviceInterfaces()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment