wlan knock daemon. Activates a wlan access point when a station knocks the airwaves right.
  • Python 91.1%
  • Roff 8.9%
Find a file
Your Name 59e3cbdfac docs: add general design section for all knockd services
Co-authored-by: aider (ollama/qwen3.8:27b) <aider@aider.chat>
2026-10-25 14:37:59 +01:00
client fixing readme 2026-10-24 23:21:46 +02:00
debian fixes 2026-10-24 23:11:09 +02:00
man build: install binary to /usr/sbin and config to /etc/knockd/wlan.yaml 2026-10-24 22:48:25 +02:00
systemd fixes 2026-10-24 23:11:09 +02:00
.gitignore fixes 2026-10-24 23:11:09 +02:00
config.yaml feat: add Scapy-based WLAN knock listener with MAC allow-list 2026-10-24 22:28:27 +02:00
CONVENTIONS.md adding conventions 2026-10-25 14:33:01 +01:00
DESIGN.md docs: add general design section for all knockd services 2026-10-25 14:37:59 +01:00
knockd_wlan.py build: install binary to /usr/sbin and config to /etc/knockd/wlan.yaml 2026-10-24 22:48:25 +02:00
README.md fixing readme 2026-10-24 23:21:46 +02:00

knockd-wlan

Passively listen for 802.11 Probe Requests targeting a hidden SSID. When a valid knock pattern is detected (N probes from an allowed MAC within a sliding time window), hostapd is started to bring up the network. An optional timeout automatically stops hostapd after a configurable period.

Prerequisites

  • Linux with a wireless NIC that supports monitor mode

  • hostapd installed and a valid config file ready

  • Python >= 3.10

  • uv (a fast Python package / project manager)

    Install uv (if not already present)

    curl -LsSf https://astral.sh/uv/install.sh | sh

Project setup

# 1. Create a virtual environment managed by uv
uv venv

# 2. Activate it (or use `uv run` for every command)
source .venv/bin/activate

# 3. Install runtime dependencies
uv pip install scapy pyyaml

Configuration

Edit config.yaml in the project root. Key fields:

Key Description
target_ssid SSID the client must probe to knock
allowed_macs List of MACs permitted to knock (empty = allow all)
knock_window Sliding window in seconds
knock_count Probes required inside the window
monitor_iface Monitor-mode interface (e.g. wlan0mon)
hostapd_conf Path to the hostapd config file
timeout Auto-stop delay in seconds (0 = disable)

Prepare the wireless interface

The script expects a monitor-mode interface. Create one before running:

# Put wlan0 into monitor mode (example)
sudo ip link set wlan0 down
sudo iw dev wlan0 interface add wlan0mon type monitor
sudo ip link set wlan0mon up

Run

# Foreground (Ctrl-C to stop)
uv run python knockd_wlan.py --config config.yaml

# Verbose / debug logging
uv run python knockd_wlan.py --config config.yaml --verbose

The script will:

  1. Passively sniff for Probe Request frames matching target_ssid.
  2. Validate the source MAC against allowed_macs.
  3. Count probes in a sliding window per MAC.
  4. On a valid knock, start hostapd with the configured file.
  5. Optionally auto-stop hostapd after timeout seconds.

Stop / cleanup

  • Send SIGINT (Ctrl-C) or SIGTERM to the script – it will gracefully stop hostapd before exiting.

  • Remove the monitor interface when done:

    sudo ip link set wlan0mon down sudo iw dev wlan0mon del sudo ip link set wlan0 up

Security notes

  • Always populate allowed_macs in production.
  • Use WPA2-PSK or 802.1X in your hostapd config so that even after the knock, a valid credential is required to associate.
  • Keep timeout reasonable to avoid leaving the AP exposed.
  • Do not log the SSID or passphrase in plain text.

Packaging (Debian / .deb)

The project ships a complete debian/ directory so you can build a native .deb package without any extra tooling beyond the standard Debian build chain.

Directory layout

debian/
  control              # package metadata & dependencies
  rules                # debhelper build rules
  install              # file-installation map
  changelog            # version history
  compat               # debhelper compatibility level (13)
  source/
    format             # "3.0 (native)"
  knockd-wlan.service  # systemd unit (installed to /lib/systemd/system/)
man/
  knockd-wlan.1        # roff manpage (installed to /usr/share/man/man1/)

Build prerequisites

sudo apt install dpkg-dev debhelper python3-scapy python3-yaml groff-base

Build the .deb

# From the project root:
dpkg-buildpackage -us -uc -b

# The resulting file will be in the parent directory:
ls ../knockd-wlan_1.0.0-1_all.deb

Install the .deb

sudo dpkg -i ../knockd-wlan_1.0.0-1_all.deb
# or
sudo apt install ./knockd-wlan_1.0.0-1_all.deb

What gets installed

Path Description
/usr/bin/knockd-wlan The Python script (executable)
/etc/knockd-wlan/config.yaml Default configuration
/lib/systemd/system/knockd-wlan.service systemd unit
/usr/share/man/man1/knockd-wlan.1 Manpage

Using the systemd service

# Enable at boot and start now
sudo systemctl enable knockd-wlan
sudo systemctl start knockd-wlan

# Check status / logs
systemctl status knockd-wlan
journalctl -u knockd-wlan -f

# Stop
sudo systemctl stop knockd-wlan

Manpage

man knockd-wlan

Bump the version

  1. Increment the version in debian/changelog (add a new stanza at the top).
  2. Rebuild with dpkg-buildpackage -us -uc -b.

Notes

  • The package is architecture-independent (Architecture: all) because it is pure Python.
  • python3-scapy and python3-yaml are declared as runtime dependencies in debian/control, so apt will pull them in automatically.
  • The systemd unit runs as root (required for monitor-mode sniffing and for starting hostapd).