I had to spend some time this week generating a Bind9 configuration file from a database. I decided to learn Python at the same time. :) This is a quick Python module that will let you build Bind9 config files in no time flat:
import Bind9Tools
hosts = [
Bind9Tools . Host ( "thedreaming.org." ,
[ "192.168.0.1" , "209.217.122.208" ],
aliases = [ "www" , "ftp" , "mail" , "tachikoma" ],
mailExchangers = [ Bind9Tools . MailExchanger ( "thedreaming.org." )]),
Bind9Tools . Host ( "lucid" , [ "192.168.0.10" ], ipv6Addresses = [ "fe80::0224:01ff:fe0f:7770" ]),
Bind9Tools . Host ( "mystic" , [ "192.168.0.11" ]),
Bind9Tools . Host ( "renegade.thedreaming.org." , [ "192.168.0.12" ]),
Bind9Tools . Host ( "www.renegade" , [ "192.168.0.13" ])
]
zone = Bind9Tools . Zone ( "thedreaming.org." , "root.thedreaming.org" , [ "thedreaming.org." ], hosts )
zoneFile = open ( 'db.thedreaming.org' , 'w' )
zone . writeZoneFile ( zoneFile )
zoneFile . close ()
zoneFile = open ( 'db.192.168.0' , 'w' )
zone . writeReverseZoneFile ( zoneFile , "192.168.0." )
zoneFile . close ()
zoneFile = open ( 'db.f.e.8.0.0.0.0.0.0.0.0.0.0.0.0.0' , 'w' )
zone . writeReverseIPv6ZoneFile ( sys . stdout , "f.e.8.0.0.0.0.0.0.0.0.0.0.0.0.0." )
zoneFile . close ()
If you find this useful, or have suggestions for improvements, drop me a line in the comments!
Please enable JavaScript to view the comments powered by Disqus.