Parsing ISC files with python (dhcpd.conf) - iscpy module -
what best way parse dhcpd.conf file looks like?
ddns-update-style none; authoritative; option domain-name "example.org" option domain-name-servers ns1.example.org, ns2.example.org subnet 172.16.31.0 netmask 255.255.255.0 { # default gateway option routers 172.16.31.10; option subnet-mask 255.255.255.0; option domain-name "aaaaaa"; option domain-name-servers 172.16.31.10; #option nis-domain "domain.org"; range dynamic-bootp 172.16.31.80 172.16.31.90; default-lease-time 21600; max-lease-time 43200; host test { hardware ethernet 00:23:8b:42:3f:d1; fixed-address 172.16.31.3; } }
i tried iscpy module:
a = iscpy.parseiscstring(open('dhcpd.conf', 'r').read())
that module makes dictionary option key , string next option value of dict. isn't works if options looks like:
option domain-name "example.org" option domain-name-servers ns1.example.org, ns2.example.org
that should be:
{'option domain-name':'example.org', 'option domain-name-servers":'ns1.example.org, ns2.example.org'}
but output is:
{'option':'domain-name-servers: ns1.example.org, ns2.example.org'}
is way better or other module? thanks
i suggest read dhcpd.conf
"completely", according each directive make data structure
, such dict
, or class, class preffered , can parse data.
Comments
Post a Comment