text
stringlengths 1
93.6k
|
|---|
# A RR as dotted quad. For consistency, this driver should
|
# return both as binary string.
|
#
|
if resp.header['tc'] == True:
|
if strict > 1:
|
raise AmbiguityWarning('DNS: Truncated UDP Reply, SPF records should fit in a UDP packet, retrying TCP')
|
try:
|
req = DNS.DnsRequest(name, qtype=qtype, protocol='tcp', timeout=(timeout))
|
resp = req.req()
|
except DNS.DNSError as x:
|
raise TempError('DNS: TCP Fallback error: ' + str(x))
|
if resp.header['rcode'] != 0 and resp.header['rcode'] != 3:
|
raise IOError('Error: ' + resp.header['status'] + ' RCODE: ' + str(resp.header['rcode']))
|
return [((a['name'], a['typename']), a['data'])
|
for a in resp.answers] \
|
+ [((a['name'], a['typename']), a['data'])
|
for a in resp.additional]
|
except AttributeError as x:
|
raise TempError('DNS ' + str(x))
|
except IOError as x:
|
raise TempError('DNS ' + str(x))
|
except DNS.DNSError as x:
|
raise TempError('DNS ' + str(x))
|
def DNSLookup_dnspython(name, qtype, tcpfallback=True, timeout=30):
|
retVal = []
|
try:
|
qtype = qtype.upper()
|
# FIXME: how to disable TCP fallback in dnspython if not tcpfallback?
|
dns_version = dns.version.MAJOR+dns.version.MINOR/100
|
if dns_version<1.16:
|
answers = dns.resolver.query(name, qtype)
|
elif dns_version<2.0:
|
answers = dns.resolver.query(name, qtype, lifetime=timeout)
|
else: # >=2.0
|
answers = dns.resolver.resolve(name, qtype, lifetime=timeout)
|
for rdata in answers:
|
if qtype == 'A' or qtype == 'AAAA':
|
retVal.append(((name, qtype), rdata.address))
|
elif qtype == 'MX':
|
retVal.append(((name, qtype), (rdata.preference, rdata.exchange)))
|
elif qtype == 'PTR':
|
retVal.append(((name, qtype), rdata.target.to_text(True)))
|
elif qtype == 'TXT' or qtype == 'SPF':
|
retVal.append(((name, qtype), rdata.strings))
|
except dns.resolver.NoAnswer:
|
pass
|
except dns.resolver.NXDOMAIN:
|
pass
|
except dns.exception.Timeout as x:
|
raise TempError('DNS ' + str(x))
|
except dns.resolver.NoNameservers as x:
|
raise TempError('DNS ' + str(x))
|
return retVal
|
try:
|
# prefer dnspython (the more complete library)
|
import dns
|
import dns.resolver # http://www.dnspython.org
|
import dns.exception
|
if not hasattr(dns.rdatatype,'SPF'):
|
# patch in type99 support
|
dns.rdatatype.SPF = 99
|
dns.rdatatype._by_text['SPF'] = dns.rdatatype.SPF
|
DNSLookup = DNSLookup_dnspython
|
except:
|
import DNS # https://launchpad.net/pydns
|
if not hasattr(DNS.Type, 'SPF'):
|
# patch in type99 support
|
DNS.Type.SPF = 99
|
DNS.Type.typemap[99] = 'SPF'
|
DNS.Lib.RRunpacker.getSPFdata = DNS.Lib.RRunpacker.getTXTdata
|
# Fails on Mac OS X? Add domain to /etc/resolv.conf
|
DNS.DiscoverNameServers()
|
DNSLookup = DNSLookup_pydns
|
RE_SPF = re.compile(br'^v=spf1$|^v=spf1 ',re.IGNORECASE)
|
# Regular expression to look for modifiers
|
RE_MODIFIER = re.compile(r'^([a-z][a-z0-9_\-\.]*)=', re.IGNORECASE)
|
# Regular expression to find macro expansions
|
PAT_CHAR = r'%(%|_|-|(\{[^\}]*\}))'
|
RE_CHAR = re.compile(PAT_CHAR)
|
RE_INVALID_MACRO = re.compile(r'(?<!%)%[^{%_-]|%$')
|
# Regular expression to break up a macro expansion
|
RE_ARGS = re.compile(r'([0-9]*)(r?)([^0-9a-zA-Z]*)')
|
RE_DUAL_CIDR = re.compile(r'//(0|[1-9]\d*)$')
|
RE_CIDR = re.compile(r'/(0|[1-9]\d*)$')
|
PAT_IP4 = r'\.'.join([r'(?:\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])']*4)
|
RE_IP4 = re.compile(PAT_IP4+'$')
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.