easy-stun is a small, fast STUN client focused on discovering your public (NAT-mapped) address/port by sending a STUN Binding Request and parsing the response. It’s designed to run continuously and keep the mapping alive, while executing optional user scripts on key events.
- NAT mapping discovery (public IP/port as seen by a STUN server)
- Keepalive to reduce NAT mapping expiration
- Event hooks via external scripts:
bind: when a mapping is discovered/updatedcr: when something that looks like a TR-111 connection request is received (currently a placeholder)
This is not a full STUN server implementation. It’s a client intended to be used as a building block in networking setups and automation.
- Creates a UDP socket (non-blocking).
- Sends a STUN Binding Request to a configured STUN server.
- Receives packets in an event-driven loop and processes STUN responses:
- extracts
MAPPED-ADDRESSorXOR-MAPPED-ADDRESS
- extracts
- Periodically sends keepalive pings to keep NAT mappings alive.
- Spawns an external script on certain events (fire-and-forget; does not block packet processing).
- C toolchain (clang or gcc)
- CMake (>= 3.5)
- Ninja (recommended) or Make
- OpenSSL development headers/libs
cmake,ninja,pkg-config,openssl@3
build-essential,cmake,ninja-build,pkg-config,libssl-dev
From the repository root:
cmake -S easy-stun -B easy-stun/build -G Ninja -DCMAKE_BUILD_TYPE=Release
cmake --build easy-stun/build
There is a helper script used by the project:
cd easy-stun
./scripts/make.sh
easy-stun expects a config file. The command line supports:
--config <path>: path to config file--fork: run as a daemon (fork + detach)
Example:
./easy-stun/build/easy-stun --config ./config.txt
./easy-stun/build/easy-stun --config ./config.txt --fork
The config file is space-delimited: <key> <value>, one per line.
Keys used by easy-stun:
local-port <port|any>- UDP port to bind locally. Use
any(or0) to let OS choose.
- UDP port to bind locally. Use
remote-addr <host>- STUN server hostname/IP.
remote-port <port>- STUN server port (typical STUN: 3478).
username <string>password <string>- Credentials used for MESSAGE-INTEGRITY (project-specific; depends on your server setup).
script <path>- Path to an executable script that will be spawned on events.
keepalive-interval <seconds>- Keepalive interval in seconds. Set to
0to disable keepalives.
- Keepalive interval in seconds. Set to
acs-addr <host>acs-port <port>- Address/port used for additional keepalive ping (useful for some deployments).
restart-interval <seconds>- If non-zero, on connection error the client waits N seconds and retries.
local-port any
remote-addr stun.example.com
remote-port 3478
username myuser
password mypass
script /usr/local/bin/easy-stun-hook.sh
keepalive-interval 30
acs-addr acs.example.com
acs-port 7547
restart-interval 5
The configured script is spawned asynchronously. Exit codes are logged when the child process exits.
The script is invoked as:
- On mapping discovery/update:
<script> bind <mapped_ip> <mapped_port>
- On “connection request” packet (currently a placeholder detector):
<script> cr <mapped_ip> <mapped_port>
MIT