mac osx 获取系统信息

获取mac地址

bool ComputerDevice::GetMacAddress(std::vector& vctMacAddress_)
{
    kern_return_t kr;
    CFMutableDictionaryRef matchDict;
    io_iterator_t iterator;
    io_registry_entry_t entry;

    matchDict = IOServiceMatching("IOEthernetInterface");
    kr = IOServiceGetMatchingServices(kIOMasterPortDefault, matchDict, &iterator);

    NSDictionary *resultInfo = nil;

    while ((entry = IOIteratorNext(iterator)) != 0)
    {
        CFMutableDictionaryRef properties=NULL;
        kr = IORegistryEntryCreateCFProperties(entry,
                                               &properties,
                                               kCFAllocatorDefault,
                                               kNilOptions);
        if (properties)
        {
            resultInfo = (NSDictionary *)properties;
            NSString *bsdName = [resultInfo objectForKey:@"BSD Name"];
            NSData *macData = [resultInfo objectForKey:@"IOMACAddress"];
            if (!macData)
            {
                continue;
            }

            NSMutableString *macAddress = [[NSMutableString alloc] init];
            const UInt8 *bytes = (const UInt8*)[macData bytes];
            for (NSUInteger i=0; i

获取CPU 序列号

std::string ComputerDevice::GetCpuIdSerial()
{
    NSProcessInfo* pinfo = [NSProcessInfo processInfo];
    NSString* ret = [pinfo globallyUniqueString];
    return [ret UTF8String];
}

获取操作系统序列号

std::string ComputerDevice::GetSoftSytemSerial()
{
    NSString * ret = nil;  
    io_service_t platformExpert ;  
    platformExpert = IOServiceGetMatchingService(kIOMasterPortDefault, IOServiceMatching("IOPlatformExpertDevice")) ;  
      
    if (platformExpert) {  
        CFTypeRef uuidNumberAsCFString ;  
        uuidNumberAsCFString = IORegistryEntryCreateCFProperty(platformExpert, CFSTR("IOPlatformSerialNumber"), kCFAllocatorDefault, 0) ;  
        if (uuidNumberAsCFString)   {  
            ret = [(NSString *)(CFStringRef)uuidNumberAsCFString copy];  
            CFRelease(uuidNumberAsCFString); uuidNumberAsCFString = NULL;  
        }  
        IOObjectRelease(platformExpert); platformExpert = 0;  
    }  
      
    std::string str = [ret UTF8String];
    [ret autorelease];
    return str;
}

获取硬盘序列号


std::string ComputerDevice::GetHardWareSerial()
{
    
    NSString *ret = nil;  
    io_service_t platformExpert ;  
    platformExpert = IOServiceGetMatchingService(kIOMasterPortDefault, IOServiceMatching("IOPlatformExpertDevice")) ;  
      
    if (platformExpert) {  
        CFTypeRef serialNumberAsCFString ;  
        serialNumberAsCFString = IORegistryEntryCreateCFProperty(platformExpert, CFSTR("IOPlatformUUID"), kCFAllocatorDefault, 0) ;  
        if (serialNumberAsCFString) {  
            ret = [(NSString *)(CFStringRef)serialNumberAsCFString copy];  
            CFRelease(serialNumberAsCFString); serialNumberAsCFString = NULL;  
        }  
        IOObjectRelease(platformExpert); platformExpert = 0;  
    }  
    std::string str = [ret UTF8String];
    [ret autorelease];
    return str;
}

深圳利程电子有限公司

你可能感兴趣的:(mac osx 获取系统信息)