- Python 91.1%
- Roff 8.9%
|
|
||
|---|---|---|
| client | ||
| debian | ||
| man | ||
| systemd | ||
| .gitignore | ||
| config.yaml | ||
| CONVENTIONS.md | ||
| DESIGN.md | ||
| knockd_wlan.py | ||
| README.md | ||
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
-
hostapdinstalled 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:
- Passively sniff for Probe Request frames matching
target_ssid. - Validate the source MAC against
allowed_macs. - Count probes in a sliding window per MAC.
- On a valid knock, start
hostapdwith the configured file. - Optionally auto-stop
hostapdaftertimeoutseconds.
Stop / cleanup
-
Send
SIGINT(Ctrl-C) orSIGTERMto the script – it will gracefully stophostapdbefore 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_macsin production. - Use WPA2-PSK or 802.1X in your
hostapdconfig so that even after the knock, a valid credential is required to associate. - Keep
timeoutreasonable 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
- Increment the version in
debian/changelog(add a new stanza at the top). - Rebuild with
dpkg-buildpackage -us -uc -b.
Notes
- The package is architecture-independent (
Architecture: all) because it is pure Python. python3-scapyandpython3-yamlare declared as runtime dependencies indebian/control, soaptwill pull them in automatically.- The systemd unit runs as root (required for monitor-mode sniffing
and for starting
hostapd).