DNS Record Generator
Generate DNS zone file entries for A, MX, TXT, CNAME, and SRV record types.
@ 3600 IN A 1.2.3.4
Frequently Asked Questions
Code Implementation
# Generate DNS zone file records programmatically
from dataclasses import dataclass
from typing import Optional
@dataclass
class DnsRecord:
name: str
record_type: str
value: str
ttl: int = 3600
priority: Optional[int] = None # For MX records
def to_zone_line(self) -> str:
if self.priority is not None:
return f"{self.name}\t{self.ttl}\tIN\t{self.record_type}\t{self.priority}\t{self.value}"
return f"{self.name}\t{self.ttl}\tIN\t{self.record_type}\t{self.value}"
records = [
DnsRecord("@", "A", "93.184.216.34"),
DnsRecord("www", "CNAME", "example.com."),
DnsRecord("@", "MX", "mail.example.com.", priority=10),
DnsRecord("@", "TXT", '"v=spf1 mx ~all"'),
DnsRecord("mail", "A", "93.184.216.35"),
]
print("$ORIGIN example.com.")
print("$TTL 3600")
for record in records:
print(record.to_zone_line())Comments & Feedback
Comments are powered by Giscus. Sign in with GitHub to leave a comment.