I have been trying to do something like logger of connects, disconnects and times connected to the access point via the Raspberry pi. What i have came up with is creating access point on the Raspberry pi 3 with dnsmasq and hostapd and getting the list of connected users (with their ip/mac) via the arp commands then running the command from python to read the list. What i am struggling with is creating a listener(monitor) in python that would listen to changes on the network -> connect or disconnect and then run the arp command to get the list and then log the change to e.g. text file or simply console(irrelevant at this point).
I would like to avoid looping every X ms in order to get the arp status since it would not give me exact information unless it runs all the time and even then the is delay in the time of response from the arp command and writing to console/file or whatever there is in the loop.
I'm wondering if anyone knows any listener that i would implement and interrupt the main program, do the work and go back to main program e.g. or any other solution regarding this?