iOS Objective C: Obtaining MAC address of an IP from ARP Table

There are many reasons where one might want to obtain a MAC address of a host (or network device) in a local area network given a valid IP address to be used in iOS application development. In computer networking, Address Resolution Protocol (ARP) is used for resolution of a network layer address into a link layer address. Typically ARP involves exchanging ARP messages to obtain MAC address of a host given that IP address of the host is known. This link provides a nice explanation of ARP.

ARP table is a cache which stores IP addresses and associated MAC addresses of the network devices. Smartphones such as Android and iOS platforms also contain an ARP table. One can view ARP table on Mac OS X by using terminal and type command:

arp -a
(10.0.0.1) at e8:fc:af:ff:99:d5 on en0 ifscope [ethernet]
(10.0.0.5) at 80:ea:96:e6:55:4f on en0 ifscope [ethernet]
(10.0.0.12) at a4:5e:60:bd:5b:2d on en0 ifscope permanent [ethernet]
(10.0.0.16) at f4:f9:51:d3:e:35 on en0 ifscope [ethernet]
(10.0.0.22) at f4:f9:51:d3:e:36 on en0 ifscope [ethernet]
(10.0.0.255) at ff:ff:ff:ff:ff:ff on en0 ifscope [ethernet]

If we could programmatically access ARP table we could also obtain a MAC address of the associated IP address. Thanks to Evgeniy Kapralov who posted arpmac project on GitHub in accessing ARP table of the iOS device programmatically.

Why do we need this? Well, iOS 8 does not provide APIs in accessing ARP table and there may be cases where one might want to programmatically determine MAC address of a network device on iOS platform.