1

I have been looking for a library that can execute an ARP (Address Resolution Protocol) command to return a list of connected devices on the network. The idea is that it would send the request to the gateway and get a list of MAC addresses of currently connected devices as a sort of "who's home" request.

I have searched around Arduino's libraries and have not found any that specifically perform this type of functionality so I was hoping that maybe it was available in a function within a broader networking library.

The particular networking interface (wifi via ESP8266/ESP32 or Ethernet) does not matter as I have not chosen a specific board for the job yet. I'm interested in any library solution that would allow me to poll the gateway to see which devices are currently online without having to buy a special device like FingBox.

Any recommendations for a library that includes this functionality or an approach that would allow me to send ARP commands over the network?

2
  • 1
    the way i do this is by looping from 0 to 255 and scanning each local IP.
    – dandavis
    Jan 20, 2020 at 5:28
  • @dandavis, I feel like that's what the DOS arp command and apps like Fing do as well. I'm thinking something like WiFi.ping()
    – tshimkus
    Jan 20, 2020 at 17:15

2 Answers 2

3

ARP isn't generally used the way you described. Per the spec, to resolve an IP address into a MAC address, you broadcast an ARP request for the IP address, and receive a unicast response from the host whose address it is - not a router. It also only resolves a single IP address in one request; it doesn't return the contents of the entire ARP cache.

While you could potentially unicast ARP requests to a router, it's anybody's guess as to whether the router would respond - it's not required to. By spec only the computer who's IP address is being queried should respond - so a router should not unless you've sent it an ARP request for its IP address. You'd also have to send one request for each IP address in the range specified by the LAN's network mask.

You're better off using SNMP, if the router supports it. SNMP can read the router's entire ARP cache with very little overhead (and very few packet exchanges).

The are SNMP implementations for the ESP32 and ESP8266, but they're likely to be difficult to use. Googling will find them for you.

2
  • Thanks, I'll take a look for SNMP libraries. I thought ARP was the name of the protocol that returns the routing tables as that is the DOS command that returns the list of connected devices. MAC addressing would be most useful as device IPs are generally subject to change.
    – tshimkus
    Jan 16, 2020 at 4:53
  • It is the name of that command, but what it returns isn't a routing table, it's the MAC address translation table of the computer you run it on, not the router. The protocol is different from the command.
    – romkey
    Jan 16, 2020 at 4:55
1

I was searching for the same function but I think you don't need to query the gateway.

My idea is to loop through all the valid ip addresses, send a ping to each one (it does not matter if they don't answer the ping), and we should have the MAC for this ip. Then check if this MAC is in a list saved in some non volatile space (may be an sd card) and if it's not in the "known peers" list, add it and send a message warning about a new device added to the network. Using the MAC address instead of the ip for identifying the devices should avoid problems with dynamic ips recognized as new.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.