kdhcpd is a lightweight DHCP server implemented in Python. It allows you to temporarily allocate IP addresses to devices in a local network with features like Grandstream-specific filtering and configurable network parameters.
- Dynamically allocate IP addresses within a specified range.
- Configurable subnet mask, gateway IP, and DNS server IP.
- Grandstream device filtering based on MAC address prefixes.
- Verbose mode for detailed logging.
- Compatible with IPv4 networks.
- Easy-to-use command-line interface for configuration.
- Python 3.7 or later
ipaddressmodule (built-in with Python 3.3+)
- Clone this repository or download the
kdhcpd.pyfile. - Ensure Python 3.7+ is installed on your system.
Run the script from the command line with appropriate arguments:
python kdhcpd.py [OPTIONS]| Option | Description | Example |
|---|---|---|
-DS |
Starting DHCP IP Address | -DS 192.168.1.10 |
-DE |
Ending DHCP IP Address | -DE 192.168.1.50 |
-n |
Subnet Mask | -n 255.255.255.0 |
-g |
Gateway IP Address | -g 192.168.1.1 |
-d |
DNS IP Address | -d 8.8.8.8 |
-G |
Provide IPs only to Grandstream devices | -G |
-V / --verbose |
Enable verbose mode for detailed logging | -V |
-v |
Print version info | -v |
Start a DHCP server for the 192.168.1.0/24 network:
python kdhcpd.py -DS 192.168.1.10 -DE 192.168.1.50 -n 255.255.255.0 -g 192.168.1.1 -d 8.8.8.8 -G -VThis configuration:
- Allocates IPs between
192.168.1.10and192.168.1.50. - Uses
255.255.255.0as the subnet mask. - Sets
192.168.1.1as the gateway. - Sets
8.8.8.8as the DNS server. - Filters requests to serve only Grandstream devices.
- Enables verbose logging for debugging.
The script supports filtering requests to allocate IPs only to Grandstream devices. It uses Organizationally Unique Identifiers (OUIs) to identify devices. Supported OUIs include:
00:0B:8200:0B:46AC:CF:23C0:74:ADEC:74:D7
- Server not stopping with
Ctrl+C: Ensure the script is running in a terminal that supports signal interruption. If the issue persists, restart the terminal. - No IP allocated: Verify that the specified IP range is within the subnet and the device matches the OUI filter.
- Verbose output missing: Use the
-Vflag to enable verbose logging.