如何以编程方式获取 iPhone 的 MAC 地址和 IP 地址?
最佳答案
注意 从 iOS7 开始,您无法再检索设备 MAC 地址。将返回一个固定值而不是实际的 MAC
我不久前偶然发现的东西。来自 here我对其进行了一些修改并清理了一些东西。
IPAddress.h
IPAddress.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\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 或单元而异。
https://stackoverflow.com/questions/677530/
相关文章:
iphone - 在 iOS 中将 HTML 转换为 NSAttributedString
objective-c - 在 Cocoa 中生成一个随机的字母数字字符串
objective-c - 拆分一个 NSString 以访问一个特定的片段
iphone - Objective-C 的 JSON 解析器比较(JSON 框架、YAJL、Tou
ios - 如何在 iOS 8 中强制 View Controller 方向?
ios - 如何获取在 UIWebView 中显示的 HTML 页面的标题?
ios - 为现有对象添加扩展名的 Swift 文件命名的最佳实践是什么?