I need to detect MAC address of devices connecting to my router (running Openwrt). The idea is when a client connects to my router wirelessly, I can get its IP address (my router runs a simple C webserver). I want to get the MAC address of the device with this IP address. I can use the command 'arp' but this lists all connection to my router but I only need the connection with the source IP address I am interested in.

- 231
- 1
- 3
- 11
2 Answers
How is the router supposed to know which of those MACs are the ones you are interested in? Check out the package "arpwatch" which triggers an event when a new MAC has been discovered. It can send email when that happens, for example. It can't decide for you which of the new addresses are those you are interested in. if "current connection" and "interested in" are identical, your webserver knows the ip address of the current connection - there are countless ways to select a line from the output, matching the ip address. In the case of openWrt, the "arp" command is merely a shell script, doing "cat /proc/net/arp" - so you don't even need to parse output of a command - you can instead look into that pseudo file.

- 2,551
- 1
- 11
- 18
One easy way is this:
cat /proc/net/arp | grep '192.168.1.112 ' | awk '{print $4}'
Replace the above IP with the one you are interested in.

- 2,724
- 2
- 30
- 25