SkillPilotAI

hostapd_cli and wavemon

One tool for each side of Wi-Fi: hostapd_cli is the command-line remote control of a Linux access point (hostapd), and wavemon is a live ncurses signal monitor on the client. Together they let you see who is connected to your AP and how strong the signal really is.

181.1 Why is it used?

  • hostapd turns the Wi-Fi card of a Linux box into an access point; hostapd_cli lets you query and control it without restarting it.
  • List connected stations (MAC, bytes, signal) and kick a misbehaving client with deauthenticate.
  • Run a script automatically on AP events such as AP-STA-CONNECTED (-a with -B).
  • wavemon shows signal level, noise and SNR live on the client, so you can move the laptop/antenna and watch the effect.
  • wavemon's scan window finds nearby APs and the least crowded channel.

181.2 How it works

  • Both hostapd and hostapd_cli come from the hostapd package (apt/dnf) and run only on Linux.
  • hostapd_cli talks to hostapd over a unix control socket, by default in /var/run/hostapd (one socket per interface).
  • Commands can be given one-shot as arguments, or you open the interactive prompt (no command) and type them.
  • wavemon is a separate package; it reads the radio via nl80211 and usually needs root.
  • Without -i, wavemon auto-detects the first wireless interface.
all_sta and deauthenticate on a Linux AP
  1. 1.hostapd runs LabAP on wlan0, channel 6

  2. 2.Phone (00:11:22:33:44:55) and laptop (00:11:22:33:44:66) associate: 2 stations

  3. 3.Admin runs hostapd_cli -i wlan0 all_sta over the unix control socket

  4. 4.Reply: one MIB block per station (MAC, bytes, signal)

  5. 5.Admin runs deauthenticate 00:11:22:33:44:55

  6. 6.hostapd sends a deauthentication frame: phone drops, laptop stays connected

hostapd does the real AP work; hostapd_cli only sends text commands and prints replies

wavemon on the client
  1. 1.LabAP (ch 6) keeps sending beacons

  2. 2.Laptop runs sudo wavemon -i wlan0

  3. 3.wavemon measures every beacon: signal -52 dBm, SNR 40 dB

  4. 4.F1 Info screen shows them as bar graphs

  5. 5.Move the laptop or antenna: the values update live

181.3 Lab note: no Wi-Fi radio

  • The lab container had only lo, cfg80211/mac80211 not loaded and no /sys/class/ieee80211, so no real AP/station output exists.
  • Only commands that exit before touching the Wi-Fi driver were run (-v, -h, connection attempts with no hostapd).
  • A seccomp profile allowed only unix sockets, so even nc failed.
Terminal
uname -rzcat /proc/config.gz | grep -E \ '^CONFIG_(CFG80211|MAC80211|UNIX)='grep -cE \ '^(cfg80211|mac80211|mac80211_hwsim) ' \ /proc/modulesls /sys/class/net; ls /sys/class/ieee80211nc -w 1 127.0.0.1 9 </dev/null
Output
$ nc -w 1 127.0.0.1 9 </dev/nullnc: socket(AF_INET,1,0): Operation not permitted

181.4 hostapd_cli: options

Terminal
hostapd -vhostapd_cli -vhostapd_cli -h
Output
   -a<file>     run in daemon mode executing the action file based on events                from hostapd   -r           try to reconnect when client socket is disconnected.                This is useful only when used with -a.   -B           run a daemon in the background
OptionExampleMeaning
-p-p /var/run/hostapdDirectory that holds the control sockets
-i-i wlan0 all_staWhich AP interface to talk to
-a-i wlan0 -a act.shRun an action script on every hostapd event
-B-B -a act.shRun as a background daemon
-hhostapd_cli -hUsage and full command list
-vhostapd_cli -vVersion (2.10 in the lab, same as hostapd)

181.5 hostapd_cli: commands

Terminal
ls /var/run/hostapdhostapd_cli -i wlan0 all_stahostapd_cli -p /var/run/hostapd \  -i wlan0 status
Output
$ hostapd_cli -i wlan0 all_staFailed to connect to hostapd - wpa_ctrl_open: No such file or directory$ hostapd_cli -p /var/run/hostapd -i wlan0 statusFailed to connect to hostapd - wpa_ctrl_open: No such file or directory
  • No hostapd was running, so /var/run/hostapd did not exist and every command failed to open the control socket.
  • The official docs have no sample all_sta output, so only the man page syntax is shown below.
Output
hostapd_cli [-p<path>] [-i<ifname>] [-a<path>] [-hvB] [command..] mib          Get MIB variables (dot1x, dot11, radius).sta <addr>   Get MIB variables for one station.all_sta      Get MIB variables for all stations.help         Get usage help.interface [ifname]   Show interfaces/select interface.level <debug level>  Change debug level.license      Show full hostapd_cli license.quit         Exit hostapd_cli.
CommandWhat it does
mibMIB variables: dot1x, dot11, radius
sta 00:11:22:33:44:55MIB variables of one station
all_staMIB variables of every associated station
deauthenticate <MAC>Kick a client (sends a deauth frame)
statusAP status of the interface
interface / interface wlan1List AP interfaces / switch to another
level 2Change hostapd debug level
help, license, quitCommand list, license, exit the prompt

181.6 wavemon: options

Terminal
wavemon -vwavemon -hwavemon -v -h
Output
$ wavemon -v -hwavemon 0.9.5Distributed under the terms of the GPLv3. usage: wavemon [ -hgv ] [ -i ifname ]  -g            Ensure screen is sufficiently dimensioned  -h            This help screen  -i <ifname>   Use specified network interface (default: auto)  -v            Print version details
UsageMeaning
sudo wavemonAuto-detected wireless interface
sudo wavemon -i wlan0Use this interface
wavemon -gCheck the terminal is big enough
wavemon -h / -vHelp or version, then exit
LC_NUMERIC=en_US.UTF-8 wavemonControls number grouping

181.7 wavemon: screens and scan sort keys

Output
F1  / i   Info: signal, noise, SNR, statsF2  / l   Level histogram (time plot)F3  / s   Scan window: APs + clientsF7  / p   Preferences, ~/.wavemonrcF8  / h   HelpF9  / a   About: release info, URLsF10 / q   Quit
Key (scan window)Sort by
a / dAscending / descending (descending lists least crowded channels)
eessid (network name)
sSignal strength
c / CChannel / channel then signal
mMAC address
o / OOpen access first / open access then signal

181.8 Common mistakes

  • Reading "Failed to connect to hostapd" as a broken card: it only means the control socket was not found (hostapd not running, or socket elsewhere: use -p).
  • Thinking deauthenticate blocks a client forever: it can reconnect immediately; use a deny list in hostapd.conf or deny_acl.
  • Running wavemon without root, or on a box with no wireless interface.
  • Forgetting -i when the AP has more than one interface.

181.9 Interview tips

  • hostapd is the daemon (beacons, authentication, WPA handshake); hostapd_cli is only a client on the unix control socket. Closing it does not affect the AP.
  • all_sta lists stations; deauthenticate kicks one, deny_acl blocks one.
  • "Failed to connect to hostapd" = control socket missing, check that hostapd runs and the -p path.
  • wavemon: F1 info (signal, noise, SNR), F2 histogram, F3 scan; sort keys are first letters (s signal, c channel).