4

I need to start an arbitrary daemon when at least one WiFi network connection exists (from clients). And stop an arbitrary daemon when there is no more connections to this AP. How to do it efficiently? For now I consider polling the results of hostapd_cli all_sta, but it seems odd. I'm sure there must be some system event which can be hooked.

2 Answers 2

8

As @beemaster said run this:

hostapd_cli -a '/onHostapdChange.sh'

With the script: onHostapdChange.sh

#!/bin/bash
if [[ $2 == "AP-STA-CONNECTED" ]]
then
  echo "someone has connected with mac id $3 on $1"
fi

if [[ $2 == "AP-STA-DISCONNECTED" ]]
then
  echo "someone has disconnected with mac id $3 on $1"
fi
1
  • What are the parameters to the command? When I tried this hostapd_cli didn't exit. Do you have to re-do this ever time the machine restarts or does it somehow remember to run the script? Jun 10, 2023 at 19:31
3

For now I've found the following solution:

hostapd_cli -a 'some_script'

Where script receives network interface name and event type as an arguments. This must be started after hostapd daemon. Also it needs ctrl_interface to be set in hostapd.conf.

1
  • This is also called on closed connection!
    – maxisme
    Dec 2, 2016 at 18:59

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .