如何以编程方式获取 iPhone 的 MAC 地址 [英] How can I programmatically get the MAC address of an iphone

查看:41
本文介绍了如何以编程方式获取 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.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
", 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆