Command
ping -c 1 192.168.1.1 > /dev/null && arp -a | grep 192.168.1.1
This returns something like this:
? (192.168.1.1) at 61:02:6a:40:34:A3 on en0 ifscope [ethernet]
How does this work?
The command pings the IP address once to make sure that your machine and the target machine communicated at least once. Because we don’t need the output of the ping command, we can simply pipe it into /dev/null. It then continues and loads all entries from ARP (Address Resolution Protocol) and “greps” the line which matches with the provided IP address.
Careful with IPv6!
ARP is IPv4 only. For IPv6 you need to use NDP (Neighbor Discovery Protocol). Simply replace “arp -a” with “ndp -a” above.