本文介绍了如何以编程方式获取 iPhone 的 MAC 地址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何以编程方式获取 iPhone 的 MAC 地址和 IP 地址?
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.
IPAddress.hIPAddress.c
并使用它
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 ", 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 地址
发布评论