3

I have an app which checks whether a certain IP is on the local network. The IP belongs to a raspberry pi working as a homeautomation device. Running the command

arp -a

from terminal or from within my app I get a list of all devices on the local network, but my raspberry pi is not always listed. After pinging the device, it appears on the list every time. Any ideas what is going wrong?

Barmar
  • 741,623
  • 53
  • 500
  • 612
heimi
  • 499
  • 7
  • 16

1 Answers1

4

That's the way ARP works. ARP entries are created only when they're needed. The first time you need to communicate with an IP on the local network, your device broadcasts an ARP query, then caches the response. There's nothing that proactively fills in the cache for all IPs on the LAN.

In addition, old entries may be removed from the cache if they haven't been used in a while.

Barmar
  • 741,623
  • 53
  • 500
  • 612
  • 1
    So there is no way to query all the ip addresses on a network at the moment? – kevin godfrey Jun 18 '21 at 04:50
  • 2
    You can enumerate all the IPs on the network based on your address and subnet mask, and then try to ping them all. Tools like `nmap` can automate this. – Barmar Jun 18 '21 at 22:19
  • 1
    But as I mentioned, if you don't keep communicating with all the IPs, they may be removed after a timeout. – Barmar Jun 18 '21 at 22:21