Query serial number
This commit is contained in:
parent
a5bb257827
commit
663133f9cb
1 changed files with 25 additions and 2 deletions
27
lib.py
27
lib.py
|
@ -9,6 +9,7 @@ import dns.rdataset
|
|||
import dns.rdatatype
|
||||
from dns.rdtypes.ANY import CNAME, DNAME, MX, NS, SOA, SSHFP, TXT
|
||||
from dns.rdtypes.IN import AAAA, SRV, A
|
||||
import dns.resolver
|
||||
|
||||
# dns name object '@'
|
||||
AT = dns.name.Name(())
|
||||
|
@ -62,6 +63,25 @@ def add_to_zone(zone, name, rdata):
|
|||
)
|
||||
rdataset.add(rdata)
|
||||
|
||||
|
||||
def get_serial(dns_zone):
|
||||
"""
|
||||
Query the serial number from the NS
|
||||
|
||||
dns_zone can either be a str or a dns.zone.Zone obj
|
||||
"""
|
||||
|
||||
try:
|
||||
answer = dns.resolver.query(dns_zone, 'soa')
|
||||
soa = answer.rrset.items[0]
|
||||
serial = soa.serial
|
||||
except:
|
||||
logging.warning(f"[GET SERIAL] failed to query serial for this zone."
|
||||
"Fallback to default value 0")
|
||||
serial = 0
|
||||
|
||||
return serial
|
||||
|
||||
def soa_handler(re2o_zone, dns_zone):
|
||||
"""Handler for SOA record"""
|
||||
|
||||
|
@ -70,14 +90,17 @@ def soa_handler(re2o_zone, dns_zone):
|
|||
|
||||
ns = re2o_zone["ns_records"][0]["target"]
|
||||
ns_obj = dns.name.from_text(ns)
|
||||
|
||||
origin = dns_zone.origin
|
||||
serial = get_serial(origin)
|
||||
logging.debug(f"[SOA] zone_origin={origin} serial={serial}")
|
||||
|
||||
soa_obj = SOA.SOA(
|
||||
dns.rdataclass.IN,
|
||||
dns.rdatatype.SOA,
|
||||
ns_obj,
|
||||
format_rname(soa["mail"]),
|
||||
#soa["serial"],
|
||||
0,
|
||||
serial,
|
||||
soa["refresh"],
|
||||
soa["retry"],
|
||||
soa["expire"],
|
||||
|
|
Loading…
Reference in a new issue