Annotation to Hardware Address

Diese Seite verwendet Cookies. Durch die Nutzung unserer Seite erklären Sie sich damit einverstanden, dass wir Cookies setzen. Weitere Informationen

  • Annotation to Hardware Address

    Ich hab das jetzt einmal in englisch geschrieben, bin zu faul, das zu übersetzen. Denke aber, das das hier gut aufgehoben ist.

    ---

    I just want to tell you my experience with this topic.
    The problem was how to get the Hardware Address of the first (built-in) ethernet card.
    There are two relatively easy way:

    1)

    Quellcode

    1. - (NSString *)getEthernetAddress
    2. {
    3. NSString *str = @"";
    4. OTInetGetInterfaceInfo(&myInetInterfaceInfo, 0);
    5. if (myInetInterfaceInfo.fHWAddrLen > 0) {
    6. for(i=0; i<myInetInterfaceInfo.fHWAddrLen; i++) {
    7. str = [str stringByAppendingFormat: @"%02x", myInetInterfaceInfo.fHWAddr[i]];
    8. }
    9. }
    10. return str;
    11. }
    Alles anzeigen


    2)

    Quellcode

    1. - (NSString *)getEthernetAddress
    2. {
    3. NSString *str, *uuid;
    4. uuid = (NSString *) CFUUIDCreateString(0, CFUUIDCreate(0));
    5. str = [[uuid componentsSeparatedByString: @"-"] lastObject];
    6. return str;
    7. }


    Do not use the second way. Normally it gives the same as the first method,
    but on some systems this can change when you (e.g.) switch between
    AirPort and LAN. The first method is "safe" in this relation.

    ---

    gruß
    MAX