获取ios的MAC地址
来源:互联网 发布:linux文件权限管理 编辑:程序博客网 时间:2024/06/04 18:47
#include <sys/socket.h> // Per msqr#include <sys/sysctl.h>#include <net/if.h>#include <net/if_dl.h>#pragma mark MAC// Return the local MAC addy// Courtesy of FreeBSD hackers email list// Accidentally munged during previous update. Fixed thanks to mlamb.- (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");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)];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 uppercaseString];}
0 0
- 获取ios的MAC地址
- 获取ios的MAC地址
- IOS的mac地址获取
- 获取ios的MAC地址
- 获取ios的MAC地址
- 获取ios的MAC地址
- 获取ios的MAC地址
- 获取ios的MAC地址
- IOS 获取MAC地址
- ios 获取mac 地址
- IOS获取mac地址
- ios Mac 地址获取
- ios获取mac地址
- ios Mac 地址获取
- iOS获取手机的Mac地址
- iOS开发:获取设备的MAC地址
- iOS 获取手机的物理(Mac地址)地址
- 获取ios设备mac地址
- Java 模板方法设计模式
- CentOS 6.5搭建SVN服务器
- Unity3D研究院之Unity中连接本地或局域网MySQL数据库(五十九)
- python中MySQLdb模块用法实例
- hadoop学习(六)--------eclipse远程调试
- 获取ios的MAC地址
- 小议随机数
- Centos 6.4 上源码安装 kamailio 4.1
- Python字符串操作
- 自测题V——Shuffling Machine(20)
- Android中设置字体颜色
- SQL92标准语句Mycat支持测试 (基于Oracle和MySQL数据库)与下载地址
- 【JavaScript好学易用系列】之二:JavaScript语法
- 杭电1521 排列组合(指数型母函数)