ISCpy a robust ISC config file parser. It has virtually unlimited possibilities for depth and quantity of ISC config files. ISC config files include BIND and DHCP config files among a few others.
The example below shows how to parse a canonical Bind configuration as generated by running named-checkonf -p
.
In [1]:
import iscpy
In [6]:
with open('named.conf') as fp:
s = fp.read()
In [9]:
config = iscpy.ParseISCString(s)
In [10]:
type(config)
Out[10]:
The config
dictionary is keyed by the different sections of the Bind configuration.
In [11]:
config.keys()[0]
Out[11]:
In [13]:
set([key.split()[0] for key in config.keys()]) # 'view' missing in this example
Out[13]:
In [18]:
acls = {key: value for key,value in config.items() if key.startswith('acl')}
zones = {key: value for key,value in config.items() if key.startswith('zone')}
# etc.
acls.keys()
Out[18]:
The sections are dictionaries again. Note that lists are converted into dictionaries with values set to True
.
In [15]:
config['zone "86.168.192.in-addr.arpa"']
Out[15]:
In [16]:
config['zone "16.172.in-addr.arpa"']
Out[16]:
In [ ]: