[Tutor] Python Bind DNS Zone config

Nathan D'Elboux nathan.delboux at gmail.com
Wed May 3 05:40:28 EDT 2017

Hi all,

I am new to python and have been studying Python 3 at uni and in my spare
time for the past 6 months or so.

I could probably do this in BASH given its on a linux system but am really
incorporating python into my daily work as much as i can, so i have chosen
python3 to implement this

What i am trying to do is have the below syntax somehow stored into a block
of strings exactly in this syntax. I dont know what data type i should be
trying to store this as, a string obviously but how would i preserve the
syntax so it outputs in the identical way? The

zone "." {
6     type master;
7     //type hint;
8     file "/etc/bind/db.root.honeypot";


In between the "." I will be asking a user for input to insert a domain in
plain ASCII and place it in that location of the zone file config and print
it to STD OUT on the terminal. Perhaps later another version of this i will
include writing directly to a file but for now i want to ensure the
inserting of string into specific position works and just print it out.

So im thinking of something along the lines of

User_input_Zone = str(input("Enter the domain you wish to block: ")

Def zone_blacklist
New_zone = "zone "{}" {, user_input_zone
6                  type master;
7                  //type hint;
8                  file "/etc/bind/db.root.honeypot";
9 };"

What i was thinking of doing is having a place holder of {} in place of
where i want the domain to be inserted into but i dont know how to
structure the syntax of a zone file in a function within

I apologise if its basic, i don't necessarily want the answer just given to
me but more of a clue of how someone else may structure it and i will
research it myself. Just want some guidance.


More information about the Tutor mailing list