Hello,
I'm trying to get a list of all network devices (device audit for DLP system).
CFMutableDictionaryRef matchingDictionary = IOServiceMatching(kIONetworkControllerClass);
if (matchingDictionary == nullptr)
{
std::cerr << "IOServiceMatching() returned empty matching dictionary" << std::endl;
return 1;
}
io_iterator_t iter;
if (kern_return_t kr = IOServiceGetMatchingServices(kIOMasterPortDefault, matchingDictionary, &iter);
kr != KERN_SUCCESS)
{
std::cerr << "IOServiceGetMatchingServices() failed" << std::endl;
return 1;
}
io_service_t networkController;
while ((networkController = IOIteratorNext(iter)) != IO_OBJECT_NULL)
{
std::cout << "network device: ";
if (CFDataRef cfIOMACAddress = (CFDataRef) IORegistryEntryCreateCFProperty(networkController, CFSTR(kIOMACAddress), kCFAllocatorDefault, kNilOptions);
cfIOMACAddress != nullptr)
{
std::vector<uint8_t> data(CFDataGetLength(cfIOMACAddress));
CFDataGetBytes(cfIOMACAddress, CFRangeMake(0, data.size()), data.data());
std::cout << std::hex << std::setfill('0') << std::setw(2) << (short)data[0] << ":"
<< std::hex << std::setfill('0') << std::setw(2) << (short) data[1] << ":"
<< std::hex << std::setfill('0') << std::setw(2) << (short) data[2] << ":"
<< std::hex << std::setfill('0') << std::setw(2) << (short) data[3] << ":"
<< std::hex << std::setfill('0') << std::setw(2) << (short) data[4] << ":"
<< std::hex << std::setfill('0') << std::setw(2) << (short) data[5];
CFRelease(cfIOMACAddress);
}
std::cout << std::endl;
IOObjectRelease(networkController);
}
IOObjectRelease(iter);
The Wi-Fi controller shows up in I/O Registry Explorer, but IOServiceGetMatchingServices() does not return any information about it.
Any way to retrieve Wi-Fi controller info in daemon code?
Thank you in advance!
3
0
153