Configure DNS using simple python scripts https://pypi.org/project/dnscode/
Find a file
minecraftchest1@outlook.com 27d483b2bb Build pipeline for doxygen.
2025-01-31 10:19:16 -06:00
.woodpecker Build pipeline for doxygen. 2025-01-31 10:19:16 -06:00
docs/html New doxygen theme. 2025-01-31 09:12:32 -06:00
doxygen-awesome-css@568f56cde6 New doxygen theme. 2025-01-31 09:12:32 -06:00
src/dnscode Add retry as negative TTL. 2025-01-27 10:37:42 -06:00
.editorconfig Initial "Commit. 2024-11-04 12:20:23 -06:00
.gitignore Setup for packaging. 2025-01-13 13:35:19 -06:00
.gitmodules New doxygen theme. 2025-01-31 09:12:32 -06:00
Doxyfile New doxygen theme. 2025-01-31 09:12:32 -06:00
LICENSE Setup for packaging. 2025-01-13 13:35:19 -06:00
pyproject.toml Bump to v1.4.1 2025-01-27 10:40:21 -06:00
README.md New doxygen theme. 2025-01-31 09:12:32 -06:00
requirements.txt Build unit tests. 2025-01-23 08:31:31 -06:00
test_dnscode.py Update tests for SOA negative TTL 2025-01-27 10:42:11 -06:00

DNScode

Simplifying DNS Zone management


About

DNScode is a project to help simplify DNS zone management, when using plain text files with servers like BIND and NSD. It provides a framework for programmatically generating zone files with Python, allowing for more flexability, compared to other DNS as code solutions.

Installation

# Create working directory
mkdir dnsproject
cd dnsproject

# Create virtual envrionment (optional, but highly recomended)
python3 -m venv .venv
source .venv/bin/activate

# Install the dnscode package
pip install dnscode

Usage

Import the dnscode package into a python script, create a zone object, then add records into the zone. Records can be added either via helper functions in the dnscode.Zone class, or by manually creating record objects and adding them through dnscode.Zone.add(). Both methods are shown in the example below.

Once the zone is setup, you can save it as a text file using dnscode.Zone.save_file(). Currently, it also outputs to to STDOUT. See #5 for details.

API docs at https://dnscode.minecraftchest1.us/classdnscode_1_1dnscode_1_1Zone

import dnscode

zone = dnscode.Zone(origin='example.com')				# Create zone object
zone.new_SOA(mname='ns1.minecraftchest1.us.',			# Create SOA
	rname='admin.minecraftchest1.us.',
	refresh=onemonth, retry=oneday, ttl=oneday)
zone.new_A(name='myhost', ttl=3600, host='0.0.0.0')		#New A record
zone.new_AAAA(name='myhost', ttl-3600, hosts='::1')
# More helper functions in the docs

cname = dnscode.CNAME(name='mycname', ttl=60, host='example.com')
# More record objects in the docs.
zone.add(cname)

zone.save_file('example.zone')