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': ''}]


.. code:: python

import pydhcpdparser

conf = """
subnet netmask {
pool {
failover peer "az-dhcp-failover";
option routers;
option broadcast-address;
option domain-name "";
option domain-name-servers,;
print pydhcpdparser.parse(conf)


.. code:: python

from pydhcpdparser import parse

conf = "zone { key DHCPUPDATE; }"
print parse(conf)


.. code:: python

from pydhcpdparser import *

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

Installing **pydhcpdparser**

.. code:: bash

$ pip install pydhcpdparser

Development installation **pydhcpdparser**

.. code:: bash

$ 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;

11. 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

.. code:: bash

$ python -m unittest discover

Project details

Download files

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

Filename, size & hash SHA256 hash help File type Python version Upload date
pydhcpdparser-0.0.8.tar.gz (13.3 kB) Copy SHA256 hash SHA256 Source None

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page