iOS 10.2中的MAC地址

时间:2016-12-22 12:56:25

标签: ios network-programming

看起来从iOS 10.2开始,Apple现在已禁止访问所有 MAC地址,而不仅仅是您自己的设备。

但是,商店中的某些应用似乎仍在管理,.e.g Fing Net Analyzer 。这些仍然有效,因为它们是针对较旧的SDK编译的,还是有特殊的技巧来收集MAC地址?

任何人都可以共享解决办法来获取WiFi上的iOS 10.2设备的MAC地址吗?

1 个答案:

答案 0 :(得分:14)

这只是测试代码,只是为了了解如何获取Mac地址。但我相信Apple很快会关闭这个选项。

-(void) jan_mac_addr_test:(const char*) host
{
    #define BUFLEN (sizeof(struct rt_msghdr) + 512)
    #define SEQ 9999
    #define RTM_VERSION 5   // important, version 2 does not return a mac address!
    #define RTM_GET 0x4 // Report Metrics
    #define RTF_LLINFO  0x400   // generated by link layer (e.g. ARP)
    #define RTF_IFSCOPE 0x1000000 // has valid interface scope
    #define RTA_DST 0x1 // destination sockaddr present
    int sockfd;
    unsigned char buf[BUFLEN];
    unsigned char buf2[BUFLEN];
    ssize_t n;
    struct rt_msghdr *rtm;
    struct sockaddr_in *sin;
    memset(buf,0,sizeof(buf));
    memset(buf2,0,sizeof(buf2));

    sockfd = socket(AF_ROUTE, SOCK_RAW, 0);
    rtm = (struct rt_msghdr *) buf;
    rtm->rtm_msglen = sizeof(struct rt_msghdr) + sizeof(struct sockaddr_in);
    rtm->rtm_version = RTM_VERSION;
    rtm->rtm_type = RTM_GET;
    rtm->rtm_addrs = RTA_DST;
    rtm->rtm_flags = RTF_LLINFO;
    rtm->rtm_pid = 1234;
    rtm->rtm_seq = SEQ;


    sin = (struct sockaddr_in *) (rtm + 1);
    sin->sin_len = sizeof(struct sockaddr_in);
    sin->sin_family = AF_INET;
    sin->sin_addr.s_addr = inet_addr(host);
    write(sockfd, rtm, rtm->rtm_msglen);

    n = read(sockfd, buf2, BUFLEN);
    if (n != 0) {
        int index =  sizeof(struct rt_msghdr) + sizeof(struct sockaddr_inarp) + 8;
        // savedata("test",buf2,n);
        NSLog(@"IP %s ::     %2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x",host,buf2[index+0], buf2[index+1], buf2[index+2], buf2[index+3], buf2[index+4], buf2[index+5]);

    }
}