ISCpy

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]:
dict

The config dictionary is keyed by the different sections of the Bind configuration.


In [11]:
config.keys()[0]


Out[11]:
'zone "86.168.192.in-addr.arpa"'

In [13]:
set([key.split()[0] for key in config.keys()])     # 'view' missing in this example


Out[13]:
{'acl', 'controls', 'key', 'logging', 'options', 'server', 'zone'}

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]:
['acl myfirstacl']

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]:
{'file': '"rev/86.168.192.in-addr.arpa"', 'type': 'master'}

In [16]:
config['zone "16.172.in-addr.arpa"']


Out[16]:
{'file': '"slave/168.192.in-addr.arpa"',
 'masters': {'192.168.17.12': True, '172.16.1.10': True},
 'type': 'slave'}

In [ ]: