Package: pydhcpdparser
pydhcpdparseris a pure python based, DHCPD configuration parser.
Built usingply, 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.ExamplesIf you input DHCPD configuration to pydhcpdparser assubnet 10.198.146.0 netmask 255.255.255.192 {
    pool {
         failover peer "az-dhcp-failover";
         range 10.198.146.4 10.198.146.62;
    }
    option routers 10.198.146.1;
    option broadcast-address 10.198.146.63;
    option domain-name "some.domain.net";
    option domain-name-servers 10.24.199.136,10.24.199.137;
}pydhcpdparserverifies DHCPD syntax, parse and return back
pythonic result as[{'netmask': '255.255.255.192',
 'option': {'broadcast-address': '10.198.146.63',
            'domain-name': '"some.domain.net"',
            'domain-name-servers': '10.24.199.136,10.24.199.137',
            'routers': '10.198.146.1'},
 'pool': {'failover': ('peer', '"az-dhcp-failover"'),
          'range': ('10.198.146.4', '10.198.146.62')},
 'subnet': '10.198.146.0'}]Usageimportpydhcpdparserconf="""
subnet 10.198.146.0 netmask 255.255.255.192 {
    pool {
         failover peer "az-dhcp-failover";
         range 10.198.146.4 10.198.146.62;
    }
    option routers 10.198.146.1;
    option broadcast-address 10.198.146.63;
    option domain-name "some.domain.net";
    option domain-name-servers 10.24.199.136,10.24.199.137;
}
"""print(pydhcpdparser.parser.parse(conf))ORfrompydhcpdparserimportparserconf="zone 17.127.10.in-addr.arpa. { key DHCPUPDATE; }"print(parser.parse(conf))ORfrompydhcpdparserimport*withopen("/etc/dhcp/dhcpd.conf")asf:conf=f.read()print(parser.parse(conf))Installingpydhcpdparser$pipinstallpydhcpdparserDevelopment installationpydhcpdparser$pipinstallpydhcpdparser-rtest-requirements.txtSupported configuration parserSubnet statementssubnet subnet-number netmask netmask {
  [ parameters ]
  [ declarations ]
}pool declarationrange statementrange [ dynamic-bootp ] low-address [ high-address];Option statementsoption name value1[, value2...];Zone declarationKey declarationkey name {
    algorithm algo;
    secret value;
};Include statementinclude "filename";Allow and Deny declarations within pool declarationsknown-clients;
unknown-clients;
dynamic bootp clients;
authenticated clients;
unauthenticated clients;
all clients;
after time;
members of "class";Allow, Deny and Ignore declarations at global scopeunknown-clients
bootp
duplicates
client-updates
leasequery
booting
declinesGlobal parameters declaration statementadandon-lease-time time;
adaptive-lease-time-threshold percentage;
always-broadcast flag;
always-reply-rfc1048 flag;
authoritative;
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...];Host block declaration statementsalways-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-munittestdiscover$python3-munittestDevelopment external referenceshttps://kb.isc.org/docs