Skip to content

Instantly share code, notes, and snippets.

@vade
Created August 5, 2011 17:11
Show Gist options
  • Save vade/1128002 to your computer and use it in GitHub Desktop.
Save vade/1128002 to your computer and use it in GitHub Desktop.
// Return the MAC address of this host, obfuscated for privacy.
// The result may be used as an ID which is unique to this host.
+ (NSString *)obfuscatedMACAddress
{
NSString *address = [NSString MACAddress];
if (!address) return nil;
const char *s = [address UTF8String];
MD5_CTX c;
MD5_Init(&c);
MD5_Update(&c, s, strlen(s) );
unsigned char hash[16];
MD5_Final(hash, &c);
UInt32 *hash32 = (UInt32*)hash;
NSString *result = [NSString stringWithFormat:@"%04x%04x%04x%04x",
hash32[0], hash32[1], hash32[2], hash32[3] ];
return result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment