Initial "Commit.

This commit is contained in:
minecraftchest1@outlook.com 2024-11-04 12:20:23 -06:00
commit 8611d10b1b
5 changed files with 87 additions and 0 deletions

12
.editorconfig Normal file
View file

@ -0,0 +1,12 @@
# EditorConfig is awesome: https://EditorConfig.org
# top-most EditorConfig file
root = true
[*]
indent_style = tab
indent_size = 4
end_of_line = crlf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = false

1
.gitignore vendored Normal file
View file

@ -0,0 +1 @@
__pycache__/

66
main.py Normal file
View file

@ -0,0 +1,66 @@
from enum import Enum
from dataclasses import dataclass, field
import time
@dataclass
class Record:
def __int__(self, name: str = '@', ttl: str = 3600, rtype: str = 'A', data: str = '0.0.0.0'):
self.rtype = rtype
self.name = name
self.data = data
self.ttl = ttl
def __str__(self):
return f"{self.name} {self.ttl} {self.rclass} {self.rtype} {self.data}"
rclass: str = 'IN'
rtype: str = 'A'
name: str = '@'
data: str = '0.0.0.0'
ttl: int = 6400
@dataclass
class SOA(Record):
def __init__(self, mname: str = 'ns1.example.com', rname: str = 'admin.example.com', serial: int = int(time.time()), refresh: int = 86400, retry: int = 7200, expire: int = 15552000, ttl: int = 21700):
self.mname = mname
self.rname = rname
self.serial = serial
self.refresh = refresh
self.retry = retry
self.expire = expire
self.ttl = ttl
def __str__(self):
return str(Record(self.name, self.ttl, f'{self.mname} {self.rname} {self.serial} {self.refresh} {self.retry} {self.expire} {self.ttl}'))
name: str = '@'
rtype: str = 'SOA'
mname: str = 'ns1.example.com'
rname: str = 'admin.example.com'
serial: int = int(time.time())
refresh: int = 86400
retry: int = 7200
expire: int = 15552000
ttl: int = 21700
@dataclass
class Zone:
records: list = field(default_factory=list)
def __str__(self):
zone: str = ''
for record in self.records:
zone.join(record)
return zone
def add(self, record: Record):
self.records.append(record)
def save_file(self, filepath: str):
with open(filepath, 'w') as file:
for record in self.records:
file.write(str(record) + '\n')
file.close()

8
test.py Normal file
View file

@ -0,0 +1,8 @@
import main
zone = main.Zone()
soa = main.SOA()
record = main.Record(data='192.168.5.254', name='localhost.example.com')
zone.add(soa)
zone.add(record)
zone.save_file('/tmp/zone.txt')

0
zone.py Normal file
View file