怎么查看iphone怎么更改mac地址的mac地址

29768人阅读
首先说明下,下面两种方法均可以获得手机的mac地址,但是有个限制,是在iOS7以下才可以获得。iOS7以后苹果对于sysctl和ioctl进行了技术处理,MAC地址返回的都是02:00:00:00:00:00。官方文档上这样写的“Twolow-level
networking APIs that used to return a MAC address now return thefixed value 02:00:00:00:00:00. The APIs in question are sysctl(NET_RT_IFLIST) and ioctl(SIOCGIFCONF). Developers using the value of the MAC address should migrate toidentifiers such as -[UIDevice
identifierForVendor].This change affects all apps running on iOS 7”。
所以在iOS7以后想要获取设备的唯一标示Mac地址已经不行了,只能用其他的代替。
下面说下两种方式:
都需要导入几个头文件
#include &sys/sysctl.h&
#include &net/if.h&
#include &net/if_dl.h&
// Return the local MAC addy
// Courtesy of FreeBSD hackers email list
// Accidentally munged during previous update. Fixed thanks to mlamb.
- (NSString *) macaddress
unsigned char
struct if_msghdr
struct sockaddr_dl
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 *)
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)];
NSLog(@&outString:%@&, outstring);
free(buf);
return [outstring uppercaseString];
- (NSString *)getMacAddress
mgmtInfoBase[6];
*msgBuffer = NULL;
unsigned char
macAddress[6];
struct if_msghdr
*interfaceMsgS
struct sockaddr_dl
*errorFlag = NULL;
// Setup the management Information Base (mib)
mgmtInfoBase[0] = CTL_NET;
// Request network subsystem
mgmtInfoBase[1] = AF_ROUTE;
// Routing table info
mgmtInfoBase[2] = 0;
mgmtInfoBase[3] = AF_LINK;
// Request link layer information
mgmtInfoBase[4] = NET_RT_IFLIST;
// Request all configured interfaces
// With all configured interfaces requested, get handle index
if ((mgmtInfoBase[5] = if_nametoindex(&en0&)) == 0)
errorFlag = @&if_nametoindex failure&;
// Get the size of the data available (store in len)
if (sysctl(mgmtInfoBase, 6, NULL, &length, NULL, 0) & 0)
errorFlag = @&sysctl mgmtInfoBase failure&;
// Alloc memory based on above call
if ((msgBuffer = malloc(length)) == NULL)
errorFlag = @&buffer allocation failure&;
// Get system information, store in buffer
if (sysctl(mgmtInfoBase, 6, msgBuffer, &length, NULL, 0) & 0)
errorFlag = @&sysctl msgBuffer failure&;
// Befor going any further...
if (errorFlag != NULL)
NSLog(@&Error: %@&, errorFlag);
return errorF
// Map msgbuffer to interface message structure
interfaceMsgStruct = (struct if_msghdr *) msgB
// Map to link-level socket structure
socketStruct = (struct sockaddr_dl *) (interfaceMsgStruct + 1);
// Copy link layer address data in socket structure to an array
memcpy(&macAddress, socketStruct-&sdl_data + socketStruct-&sdl_nlen, 6);
// Read from char array into a string object, into traditional Mac address format
NSString *macAddressString = [NSString stringWithFormat:@&%02x:%02x:%02x:%02x:%02x:%02x&,
macAddress[0], macAddress[1], macAddress[2],
macAddress[3], macAddress[4], macAddress[5]];
NSLog(@&Mac Address: %@&, macAddressString);
// Release the buffer memory
free(msgBuffer);
return macAddressS
参考知识库
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:943728次
积分:4392
积分:4392
排名:第5439名
原创:34篇
转载:66篇
评论:285条
(1)(4)(4)(1)(1)(1)(4)(4)(2)(3)(2)(3)(2)(1)(4)(7)(2)(3)(2)(2)(2)(1)(4)(5)(3)(4)(1)(1)(1)(1)(2)(6)(1)(2)(1)(7)(6)搜索 新闻 资讯 游戏
您现在的位置:&&>>&&>>&&>>&&>>&正文
巴士小白福音之Mac&OS&X查看本机Mac地址方法
编辑:UNICORN && 来源:iPhone中文网 && 发布时间: 11:45:06
  【巴士小白福音】许多时候我们需要通过我们本机的Mac地址来完成一些设置。而如何查看本机的Mac地址呢?让我们通过本篇教程了解下。
  苹果电脑设备 Mac Address 查看步骤如下:
  1. 点击左上角苹果图表,选择[关于本机]
  2. 点击[更多信息]
  3. 点击[系统报告]
  4. 左侧选择[网络]-[位置]
  5. 右侧详细内容 Wifi栏下方则看查看对应硬件 Mac 地址
扫描左侧二维码,可以订阅iPhone中文网官方微信。每天除了推送最新的苹果产品资讯,我们还将不定期举行有奖活动,广大网友可以积极参与,幸运随时会降临!当然,你也可微信搜索“iPhone中文网”或“apple4cn”,关注iPhone中文网官方微信,第一时间获取更多苹果资讯。
iOS越狱破解
苹果产品信息查询
热门新闻排行
皖公网安备05 皖网文许字[3号
TGBUS Corporation, All Rights Reserved

我要回帖

更多关于 网件路由器mac地址过滤 的文章

 

随机推荐