Skip to main content

DHCP configuration file parser

Project description

pydhcpdparser is a pure python based, DHCPD configuration parser. Built using ply, lex and yacc parsing tool, pydhcpdparser can be used to verify syntax of DHCPD configurations, parse and extract values from configuration files and access them as python variables.


If you input DHCPD configuration to pydhcpdparser as

subnet netmask {
    pool {
         failover peer "az-dhcp-failover";
    option routers;
    option broadcast-address;
    option domain-name "";
    option domain-name-servers,;

pydhcpdparser verifies DHCPD syntax, parse and return back pythonic result as

[{'netmask': '',
 'option': {'broadcast-address': '',
            'domain-name': '""',
            'domain-name-servers': ',',
            'routers': ''},
 'pool': {'failover': ('peer', '"az-dhcp-failover"'),
          'range': ('', '')},
 'subnet': ''}]


import pydhcpdparser

conf = """
subnet netmask {
    pool {
         failover peer "az-dhcp-failover";
    option routers;
    option broadcast-address;
    option domain-name "";
    option domain-name-servers,;


from pydhcpdparser import parser

conf = "zone { key DHCPUPDATE; }"


from pydhcpdparser import *

with open("/etc/dhcp/dhcpd.conf") as f:
    conf =

Installing pydhcpdparser

$ pip install pydhcpdparser

Development installation pydhcpdparser

$ pip install pydhcpdparser -r test-requirements.txt

Supported configuration parser

  1. Subnet statements

    subnet subnet-number netmask netmask {
      [ parameters ]
      [ declarations ]
  2. pool declaration

  3. range statement

    range [ dynamic-bootp ] low-address [ high-address];
  4. Option statements

    option name value1[, value2...];
  5. Zone declaration

  6. Key declaration

    key name {
        algorithm algo;
        secret value;
  7. Include statement

    include "filename";
  8. Allow and Deny declarations within pool declarations

    dynamic bootp clients;
    authenticated clients;
    unauthenticated clients;
    all clients;
    after time;
    members of "class";
  9. Allow, Deny and Ignore declarations at global scope

  10. Global parameters declaration statement

adandon-lease-time time;
adaptive-lease-time-threshold percentage;
always-broadcast flag;
always-reply-rfc1048 flag;
not authoritative;
boot-unknown-clients flag;
db-time-format [ default | local ] ;
ddns-domainname name;
ddns-rev-domainname name;
ddns-update-style style;
ddns-updates flag;
default-lease-time time;
delayed-ack count;
max-ack-delay microseconds;
do-forward-updates flag;
dynamic-bootp-lease-cutoff date;
dynamic-bootp-lease-length length;
filename "filename";
get-lease-hostnames flag;
infinite-is-reserved flag;
lease-file-name name;
limit-addrs-per-ia number;
dhcpv6-lease-file-name name;
local-port port;
local-address address;
log-facility facility;
max-lease-time time;
min-lease-time time;
min-secs seconds;
next-server server-name;
omapi-port port;
one-lease-per-client flag;
pid-file-name name;
dhcpv6-pid-file-name name;
ping-check flag;
ping-timeout seconds;
preferred-lifetime seconds;
remote-port port;
server-identifier hostname;
server-duid LLT [ hardware-type timestamp hardware-address ] ;
server-duid EN enterprise-number enterprise-identifier ;
server-duid LL [ hardware-type hardware-address ] ;
server-name name ;
dhcpv6-set-tee-times flag;
site-option-space name ;
stash-agent-options flag;
update-conflict-detection flag;
update-optimization flag;
update-static-leases flag;
use-host-decl-names flag;
use-lease-addr-for-default-route flag;
vendor-option-space string;
option name value1[, value2...];
  1. Host block declaration statements
always-reply-rfc1048 flag;
ddns-hostname name;
ddns-domainname name;
fixed-address address [, address ... ];
fixed-address6 ip6-address ;
fixed-prefix6 low-address / bits;
hardware hardware-type hardware-address;

Unit testing

$ python -m unittest discover
$ python3 -m unittest

Development external references

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for pydhcpdparser, version 0.0.10
Filename, size File type Python version Upload date Hashes
Filename, size pydhcpdparser-0.0.10.tar.gz (13.6 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page