1 import dns.resolver
2 import dns.exception
3 import spf
4
5 if not hasattr(dns.rdatatype,'SPF'):
6
7 dns.rdatatype.SPF = 99
8 dns.rdatatype._by_text['SPF'] = dns.rdatatype.SPF
9
11 retVal = []
12 try:
13 answers = dns.resolver.query(name, qtype)
14 for rdata in answers:
15 if qtype == 'A' or qtype == 'AAAA':
16 retVal.append(((name, qtype), rdata.address))
17 elif qtype == 'MX':
18 retVal.append(((name, qtype), (rdata.preference, rdata.exchange)))
19 elif qtype == 'PTR':
20 retVal.append(((name, qtype), rdata.target.to_text(True)))
21 elif qtype == 'TXT' or qtype == 'SPF':
22 retVal.append(((name, qtype), rdata.strings))
23 except dns.resolver.NoAnswer:
24 pass
25 except dns.resolver.NXDOMAIN:
26 pass
27 except dns.exception.DNSException,x:
28 raise spf.TempError,'DNS ' + str(x)
29 return retVal
30
31 spf.DNSLookup = DNSLookup
32