dns-check-py/serial.py

28 lines
801 B
Python
Raw Permalink Normal View History

2023-11-30 14:53:37 +01:00
import dns.query
import dns.zone
def get_dns_serial(zone_name, nameserver):
try:
# Query the nameserver for the zone
response = dns.query.tcp(dns.message.make_query(zone_name, dns.rdatatype.SOA), nameserver)
# Parse the response
answer = dns.zone.from_text(response.answer[0].to_text(), zone_name)
serial = answer.get_rdataset(zone_name, dns.rdatatype.SOA)[0].serial
return serial
except Exception as e:
print(f"Error: {e}")
return None
# Example usage
zone_name = "0x5e.eu"
nameserver = "ns1.it53.nl" # Use the desired nameserver's IP address
serial = get_dns_serial(zone_name, nameserver)
if serial:
print(f"The DNS serial for {zone_name} is {serial}")
else:
print(f"Failed to fetch DNS serial for {zone_name}")