Unikalny identyfikator sprzętu w Mac OS X

Rozwój Mac OS X jest dla mnie dość nowym zwierzęciem i jestem w trakcie przenoszenia jakiegoś oprogramowania. W celu licencjonowania i rejestracji oprogramowania muszę być w stanie wygenerować jakiś Identyfikator sprzętu. To nie musi być nic wymyślnego; Ethernet adres MAC, dysk twardy serial, CPU serial, coś w tym stylu.

Mam to pokryte na Windows, ale nie mam pojęcia o Mac. Każdy pomysł, co muszę zrobić, lub Gdzie mogę się udać po informacje na ten temat byłby świetny!

Edit:

Dla każdego, kto jest tym zainteresowany, jest to kod, którego użyłem z klasą QProcess Qt:

QProcess proc;

QStringList args;
args << "-c" << "ioreg -rd1 -c IOPlatformExpertDevice |  awk '/IOPlatformUUID/ { print $3; }'";
proc.start( "/bin/bash", args );
proc.waitForFinished();

QString uID = proc.readAll();

Uwaga: używam C++.

Author: Peter Mortensen, 2009-06-01

8 answers

Spróbuj użyć polecenia Terminal:

ioreg -rd1 -c IOPlatformExpertDevice | awk '/IOPlatformUUID/ { split($0, line, "\""); printf("%s\n", line[4]); }'

From here

Oto polecenie zawinięte w kakao (które może być nieco czystsze):

NSArray * args = [NSArray arrayWithObjects:@"-rd1", @"-c", @"IOPlatformExpertDevice", @"|", @"grep", @"model", nil];
NSTask * task = [NSTask new];
[task setLaunchPath:@"/usr/sbin/ioreg"];
[task setArguments:args];

NSPipe * pipe = [NSPipe new];
[task setStandardOutput:pipe];
[task launch];

NSArray * args2 = [NSArray arrayWithObjects:@"/IOPlatformUUID/ { split($0, line, \"\\\"\"); printf(\"%s\\n\", line[4]); }", nil];
NSTask * task2 = [NSTask new];
[task2 setLaunchPath:@"/usr/bin/awk"];
[task2 setArguments:args2];

NSPipe * pipe2 = [NSPipe new];
[task2 setStandardInput:pipe];
[task2 setStandardOutput:pipe2];
NSFileHandle * fileHandle2 = [pipe2 fileHandleForReading];
[task2 launch];

NSData * data = [fileHandle2 readDataToEndOfFile];
NSString * uuid = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
 14
Author: xyz,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2011-07-08 07:49:44

Dla C / C++:

void get_platform_uuid(char * buf, int bufSize) {
    io_registry_entry_t ioRegistryRoot = IORegistryEntryFromPath(kIOMasterPortDefault, "IOService:/");
    CFStringRef uuidCf = (CFStringRef) IORegistryEntryCreateCFProperty(ioRegistryRoot, CFSTR(kIOPlatformUUIDKey), kCFAllocatorDefault, 0);
    IOObjectRelease(ioRegistryRoot);
    CFStringGetCString(uuidCf, buf, bufSize, kCFStringEncodingMacRoman);
    CFRelease(uuidCf);    
}
 32
Author: yairchu,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2010-05-02 18:56:51

Dlaczego nie spróbować gethostuuid()? Oto dokumentacja z podręcznika wywołań systemowych Mac OS X:

Nazwa:

 gethostuuid -- return a unique identifier for the current machine

SYNOPSIS:

 #include <unistd.h>

 int gethostuuid(uuid_t id, const struct timespec *wait);

Opis:

Funkcja gethostuuid() zwraca 16-bajtowy uuid_t określony przez id, który jednoznacznie identyfikuje bieżącą maszynę. Należy pamiętać, że identyfikatory sprzętowe, których gethostuuid() używa do generowania UUID, mogą być modyfikowane.

Argument wait jest wskaźnikiem do struktury timespec, która określa maksymalny czas oczekiwania na wynik. Ustawienie pól tv_sec i tv_nsec na zero oznacza czekanie w nieskończoność aż zakończy się.

ZWRACANE WARTOŚCI:

Funkcja gethostuuid() zwraca zero w przypadku powodzenia lub -1 W przypadku błędu.

Błędy

Funkcja gethostuuid() nie działa, Jeśli:

 [EFAULT]           wait points to memory that is not a valid part of the
                    process address space.

 [EWOULDBLOCK]      The wait timeout expired before the UUID could be
                    obtained.
 7
Author: zhanglin,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2014-04-02 03:11:41

Byłoby łatwiej odpowiedzieć, gdybyś powiedział nam, jakiego języka używasz. Informacje te można uzyskać bez żadnych poleceń powłoki poprzez SystemConfiguration framework, a także poprzez IOKit, jeśli chcesz naprawdę zabrudzić sobie ręce.

- (NSString*) getMACAddress: (BOOL)stripColons {
    NSMutableString         *macAddress         = nil;
    NSArray                 *allInterfaces      = (NSArray*)SCNetworkInterfaceCopyAll();
    NSEnumerator            *interfaceWalker    = [allInterfaces objectEnumerator];
    SCNetworkInterfaceRef   curInterface        = nil;

    while ( curInterface = (SCNetworkInterfaceRef)[interfaceWalker nextObject] ) {
        if ( [(NSString*)SCNetworkInterfaceGetBSDName(curInterface) isEqualToString:@"en0"] ) {
            macAddress = [[(NSString*)SCNetworkInterfaceGetHardwareAddressString(curInterface) mutableCopy] autorelease];

            if ( stripColons == YES ) {
                [macAddress replaceOccurrencesOfString: @":" withString: @"" options: NSLiteralSearch range: NSMakeRange(0, [macAddress length])];
            }

            break;
        }
    }

    return [[macAddress copy] autorelease];
}
 7
Author: Azeem.Butt,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2015-01-26 15:27:37
/*
g++ mac_uuid.cpp -framework CoreFoundation -lIOKit
*/


#include <iostream>
#include <IOKit/IOKitLib.h>

using namespace std;

void get_platform_uuid(char * buf, int bufSize)
{
   io_registry_entry_t ioRegistryRoot = IORegistryEntryFromPath(kIOMasterPortDefault, "IOService:/");
   CFStringRef uuidCf = (CFStringRef) IORegistryEntryCreateCFProperty(ioRegistryRoot, CFSTR(kIOPlatformUUIDKey), kCFAllocatorDefault, 0);
   IOObjectRelease(ioRegistryRoot);
   CFStringGetCString(uuidCf, buf, bufSize, kCFStringEncodingMacRoman);
   CFRelease(uuidCf);
}

int main()
{
   char buf[512] = "";
   get_platform_uuid(buf, sizeof(buf));
   cout << buf << endl;
}
 5
Author: Nitinkumar Ambekar,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2013-12-20 14:52:06

Running:

system_profiler | grep 'Serial Number (system)'

W terminalu zwraca unikalny identyfikator. To działa na moim pudełku 10.5, nie jestem pewien, jaki poprawny ciąg będzie w innych wersjach OS X.

 1
Author: kbyrd,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2009-06-01 03:43:55

Jak podpowiedziały niektóre osoby powyżej, możesz użyć polecenia Terminal, aby uzyskać identyfikator sprzętu.

Zakładam, że chcesz to zrobić w kodzie, więc rzucę okiem na klasę Nstask w Cocoa. Zasadniczo pozwala na uruchamianie poleceń terminala wewnątrz aplikacji.

Ten kod jest przykładem użycia NSTask w Cocoa. Ustawia środowisko do wykonania polecenia "killall". Przechodzi przez nią tzw. "Finder".

Jest to równoznaczne z uruchomieniem "killall Finder" na linia poleceń, która oczywiście zabije Findera.

NSTask *aTask = [[NSTask alloc] init];
NSMutableArray *args = [NSMutableArray array];

[aTask setLaunchPath: @"/usr/bin/killall"];
[args addObject:[@"/Applications/Finder" lastPathComponent]];
[aTask setArguments:args];
[aTask launch];

[aTask release];
 1
Author: Brock Woolf,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2009-10-17 06:16:20

System Profiler (w aplikacjach - narzędziach) zawiera większość tego typu informacji. Ma numer seryjny i adres mac (nie ma związku z komputerem Mac. Wszystkie komputery mają adres mac, który jest prawie unikalny dla każdej karty sieciowej).

 0
Author: Singletoned,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2009-06-03 10:30:52