Skip to content

Commit

Permalink
handle when SOA records is in the Authorative section of a response.
Browse files Browse the repository at this point in the history
  • Loading branch information
darkoperator committed Feb 17, 2015
1 parent c26ea42 commit 7b7c7b3
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions lib/dnshelper.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import dns.query
import dns.resolver
import dns.reversename
import dns.message
import socket
from dns.zone import *
from dns.dnssec import algorithm_to_text
Expand Down Expand Up @@ -170,12 +171,22 @@ def get_soa(self):
address of the host both in IPv4 and IPv6. Returns an Array.
"""
soa_records = []
answers = self._res.query(self._domain, 'SOA')
for rdata in answers:
name = rdata.mname.to_text()
ipv4_answers = self._res.query(name, 'A')
for ardata in ipv4_answers:
soa_records.append(['SOA', name[:-1], ardata.address])
query = dns.message.make_query(self._domain, dns.rdatatype.SOA)
try:
response = dns.query.udp(query, self._res.nameservers[0], self._res.timeout)
if len(response.answer) > 0:
answers = response.answer
elif len(response.authority) > 0:
answers = response.authority
for rdata in answers:
# A zone only has one SOA record so we select the first.
name = rdata[0].mname.to_text()
ipv4_answers = self._res.query(name, 'A')
for ardata in ipv4_answers:
soa_records.append(['SOA', name[:-1], ardata.address])
except (dns.resolver.NXDOMAIN, dns.exception.Timeout, dns.resolver.NoAnswer, socket.error, dns.query.BadResponse):
print_error('Error while resolving SOA record.')
return soa_records

try:
for rdata in answers:
Expand Down

0 comments on commit 7b7c7b3

Please sign in to comment.