1. DNS/実装/python/dnslib/example

>>> a.rname

<DNSLabel: 'abc.com.'>

>>> for rr in RR.fromZone(z): ... print(rr) ...

abc.com.                300     IN      MX      10 mail.abc.com.
www.abc.com.            300     IN      A       1.2.3.4
www.abc.com.            300     IN      TXT     "Some ttt"
mail.abc.com.           300     IN      CNAME   www.abc.com.

>>> z

'\n$TTL 300\n$ORIGIN abc.com\n\n@ IN MX 10 mail.abc.com.\nwww IN A 1.2.3.4\n   IN TXT "Some ttt"\nmail IN CNAME www.abc.com.\n'

>>> print (z)

$TTL 300
$ORIGIN abc.com

@ IN MX 10 mail.abc.com.
www IN A 1.2.3.4
   IN TXT "Some ttt"
mail IN CNAME www.abc.com.

1.1. read zone file

import sys
import time
import datetime
import threading
import traceback
import SocketServer

import dnslib
from dnslib import QTYPE, SOA, NS, A, AAAA, MX, CNAME
from dnslib import DNSRecord, DNSHeader, RR, RCODE

z = 'home.qmail.jp.'
IP= '192.168.10.7'
TTL = 60 * 5
PORT = 53

zone ={}

zfile = open('zone.txt')
ztxt = zfile.read()
print(ztxt)
print '-----'
zonerr= RR.fromZone(ztxt)
for rr in zonerr:
  zone[str(rr.rname)] = rr
# -----
print (zone)

1.2. zone.txt

$TTL 300
$ORIGIN home.qmail.jp.

@ IN MX 10 mail
www IN A 1.2.3.4
   IN TXT "Some txt"
mail IN CNAME www

MoinQ: DNS/実装/python/dnslib/example/zone (last edited 2020-08-24 06:31:42 by ToshinoriMaeno)