A random image with network cables

iOS — What’s your physical address?

Do you need postal code also?

Michael Mavris
Published in
2 min readJun 8, 2016

--

If you ask people not related with IT, “What’s your physical address?”, they will probably tell you their house’s address. But on this article we will discuss about the MAC Addresses on your local network and how to retrieve them using iOS.

ARP Table and API

So, I was trying to develop a network scanner for my project (IT Buddy) when I realised that Apple doesn’t provide us with an API to access the ARP (Address Resolution Protocol) table of our iOS Devices.

After spending a lot of time on Google and StackOverflow I came up with my own complete solution which I would like to share with you.

Getting the necessary files

First you will need to copy some files from you Mac OS X to your Xcode project. Go to /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk/usr/include (where MacOSX10.11.sdk is your Mac OS Version eg. MacOSX10.10.sdk).

Then from “net” folder drag n drop the route.h, if_arp.h, if_types.h and from the “netinet” folder the if_ether.h into your Xcode project. Select “Copy items if needed”.

Now we need to edit the “if_ether.h”. Find that line “#include <net/if_arp.h>” and replace it with “#include “if_arp.h”

Then import the MacFinder.h:

and MacFinder.m:

Working with MacFinder

After importing MacFinder.h in your controller you can get the MAC Address of any IP in your network with the following code:

NSString *mac = [MacFinder ip2mac:”192.168.10.24"]; 

NSLog(@”Mac:%@”,mac);

You can download the full project here if you are having trouble with the files or the implementation.

--

--

Michael Mavris

A curious Mobile Software Engineer. Loves ski, football and rock music!