- (NSString *) macaddress{
    
    int                 mib[6];
    size_t              len;
    char                *buf;
    unsigned char       *ptr;
    struct if_msghdr    *ifm;
    struct sockaddr_dl  *sdl;
    
    mib[0] = CTL_NET;
    mib[1] = AF_ROUTE;
    mib[2] = 0;
    mib[3] = AF_LINK;
    mib[4] = NET_RT_IFLIST;
    
    if ((mib[5] = if_nametoindex("en0")) == 0) {
        printf("Error: if_nametoindex error\n");
        return NULL;
    }
    
    if (sysctl(mib, 6, NULL, &len, NULL, 0) < 0) {
        printf("Error: sysctl, take 1\n");
        return NULL;
    }
    
    if ((buf = malloc(len)) == NULL) {
        printf("Could not allocate memory. error!\n");
        return NULL;
    }
    
    if (sysctl(mib, 6, buf, &len, NULL, 0) < 0) {
        printf("Error: sysctl, take 2");
        free(buf);
        return NULL;
    }
    
    ifm = (struct if_msghdr *)buf;
    sdl = (struct sockaddr_dl *)(ifm + 1);
    ptr = (unsigned char *)LLADDR(sdl);
    NSString *outstring = [NSString stringWithFormat:@"%02X:%02X:%02X:%02X:%02X:%02X",
                           *ptr, *(ptr+1), *(ptr+2), *(ptr+3), *(ptr+4), *(ptr+5)];
    free(buf);
    
    return outstring;
}

- (NSString *) uniqueDeviceIdentifier{
    NSString *macaddress = [[UIDevice currentDevice] macaddress];
    NSString *bundleIdentifier = [[NSBundle mainBundle] bundleIdentifier];
    
    NSString *stringToHash = [NSString stringWithFormat:@"%@%@",macaddress,bundleIdentifier];
    NSString *uniqueIdentifier = [stringToHash stringFormatMD5];
    
    return uniqueIdentifier;
}

- (NSString *) uniqueGlobalDeviceIdentifier{
    NSString *macaddress = [[UIDevice currentDevice] macaddress];
    NSString *uniqueIdentifier = [macaddress stringFormatMD5];
    
    return uniqueIdentifier;
}

- (NSString *)uniqueIdentifierForVendor
{
    NSString *identifierForVendor = [[[UIDevice currentDevice] identifierForVendor]UUIDString];

NSString *md5identifierForVendor = [identifierForVendor stringFormatMD5];
    
    return md5identifierForVendor;
}

+ (NSString *)getDeviceId
{
    if (IOS_VERSION<7)
    {
        return [[UIDevice currentDevice] uniqueGlobalDeviceIdentifier];
    }
    else
    {
        return [[UIDevice currentDevice] uniqueIdentifierForVendor];
    }
}

[ios2] 获取mac地址 等唯一标识的更多相关文章

  1. php怎么获取mac地址?

    如何用php获取mac地址呢?大家知道mac地址是电脑在全球范围的唯一标识,所以这个就非常实用,比如说要做一个投票功能,那mac地址是必不可少 的,如果单纯的靠ip地址来判断这个肯定是不准确的,水分太 ...

  2. Android开发 - 获取Android设备的唯一标识码(Android 6.0或更高)

    在我们的APP开发中,通常需要获取到设备的唯一标识.在Android6.0之前,有很多方法我们可以方便获取到硬件的唯一标识,但是在Android6.0之后,Android系统大幅限制了我们获取设备的硬 ...

  3. iOS7以下设备获取mac地址

    注意,是iOS7以下的设备,直接上源码,获取mac地址都是为了唯一标识一个设备的,但iOS7设备的mac地址为 020000000000 MacAddress.h #include <sys/s ...

  4. C# 获取MAC地址

    /********************************************************************** * C# 获取MAC地址 * 说明: * 在C#中获取本 ...

  5. c++ windows 获取mac地址

    c++ windows 获取mac地址 GetAdaptersInfo 用windows api获取mac地址和硬盘id编号 aa

  6. python 获取 mac 地址 的代码

    python 获取 mac 地址 的例子,有需要的朋友可以参考下. #!/bin/python import os import re def GetMac():     if os.name ==  ...

  7. Java根据ip地址获取Mac地址,Java获取Mac地址

    Java根据ip地址获取Mac地址,Java获取Mac地址 >>>>>>>>>>>>>>>>>&g ...

  8. android获取Mac地址和IP地址

    获取Mac地址实际项目中测试了如下几种方法:(1)设备开通Wifi连接,获取到网卡的MAC地址(但是不开通wifi,这种方法获取不到Mac地址,这种方法也是网络上使用的最多的方法) //根据Wifi信 ...

  9. js 获取mac地址

    js 获取mac地址 function MacInfo(){ var locator =new ActiveXObject ("WbemScripting.SWbemLocator" ...

随机推荐

  1. CSS学习笔记:transition

    CSS3的transition允许CSS的属性值在一定的时间区间内平滑地过渡.这种效果可以在鼠标单击.获得焦点.被点击或对元素任何改变中触发,并圆滑地以动画效果改变CSS的属性值. 1.transit ...

  2. javascript 学习总结(五)Function对象

    1.Function  函数调用(类似call方法) function callSomeFunction(someFunction, someArgument){ return someFunctio ...

  3. Android高仿雅虎天气(两)---代码结构分析

    版本已经升级到1.0.1 源码地址: GitHub:https://github.com/way1989/WayHoo OsChina:http://git.oschina.net/way/WayHo ...

  4. 网页头一定要加的代码段(加注版)一行代码解决各种IE兼容问题,IE6,IE7,IE8,IE9,IE10

      网页头部常见的一段代码 <!--[if lt IE 7 ]><html class="ie6"><![endif]--> <!--[i ...

  5. 使用fixed制作浮动广告(注意:解决闪屏问题,但适用于高版本浏览器,低版本的浏览器不适用)

    <script language="javascript" type="text/javascript"> //隐藏广告 function clos ...

  6. 【转载】如何让Chrome浏览器允许本地环境支持Ajax

    转载自:http://www.bewxx.com/news/news_89.html 对于网站前端人员来说,我们在本地开发程序的时候如果用到Ajax的话,通常会使用Firefox来测试,因为Firef ...

  7. C++ Builder中splitter控件的使用方法简介

    C++ Builder提供了一个Splitter控件来实现对用户窗口的分割,只需拖动该控件到窗体上,就可以实现窗口的任意分割.把面板控件(Panel)拖动到窗体上,设置其对齐方式,然后把Splitte ...

  8. JS函数实现金额小写转大写

    ///<summery>小写金额转化大写金额</summery> function AmountLtoU(amount) { if (isNaN(amount) || amou ...

  9. 基本功能的shell

    手把手教你编写一个具有基本功能的shell(已开源) 刚接触Linux时,对shell总有种神秘感:在对shell的工作原理有所了解之后,便尝试着动手写一个shell.下面是一个从最简单的情况开始,一 ...

  10. 一种最坏情况线性运行时间的选择算法 - The missing worst-case linear-time Select algorithm in CLRS.

    一种最坏情况线性运行时间的选择算法 - The missing worst-case linear-time Select algorithm in CLRS. 选择算法也就是求一个无序数组中第K大( ...