如何以编程方式获取iphone的MAC地址 [英] How can I programmatically get the MAC address of an iphone
本文介绍了如何以编程方式获取iphone的MAC地址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有谁知道如何以编程方式获取iPhone的MAC地址和IP地址?
Does anyone know how to programmatically get an iPhone's MAC address and IP address?
推荐答案
注意从iOS7开始,您无法再检索设备MAC地址。将返回一个固定值,而不是实际的MAC
NOTE As of iOS7, you can no longer retrieve device MAC addresses. A fixed value will be returned rather than the actual MAC
我偶然发现的事情。最初来自这里我修改了它有点干净了。
Somthing I stumbled across a while ago. Originally from here I modified it a bit and cleaned things up.
使用它
InitAddresses();
GetIPAddresses();
GetHWAddresses();
int i;
NSString *deviceIP = nil;
for (i=0; i<MAXADDRS; ++i)
{
static unsigned long localHost = 0x7F000001; // 127.0.0.1
unsigned long theAddr;
theAddr = ip_addrs[i];
if (theAddr == 0) break;
if (theAddr == localHost) continue;
NSLog(@"Name: %s MAC: %s IP: %s\n", if_names[i], hw_addrs[i], ip_names[i]);
//decided what adapter you want details for
if (strncmp(if_names[i], "en", 2) == 0)
{
NSLog(@"Adapter en has a IP of %s", ip_names[i]);
}
}
适配器名称也因模拟器/设备而异作为设备上的wifi或单元格。
Adapter names vary depending on the simulator/device as well as wifi or cell on the device.
这篇关于如何以编程方式获取iphone的MAC地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文