Tested with pydns

This commit is contained in:
Stuart D. Gathman
2011-06-16 19:05:33 -04:00
parent fcc50192c4
commit 5142ee9ed4
+16 -19
View File
@@ -16,11 +16,7 @@ MAX_CNAME = 10
# @param tcpfallback if False, raise exception instead of TCP fallback # @param tcpfallback if False, raise exception instead of TCP fallback
# @return a list of ((name,type),data) tuples # @return a list of ((name,type),data) tuples
def DNSLookup(name, qtype, tcpfallback=True, timeout=30): def DNSLookup(name, qtype, tcpfallback=True, timeout=30):
try: raise NotImplementedError('No supported dns library found')
install_dnspython() # prefer dnspython (the more complete library)
except:
install_pydns() # the lightweight library
return DNSLookup(name, qtype, tcpfallback, timeout)
class Session(object): class Session(object):
"""A Session object has a simple cache with no TTL that is valid """A Session object has a simple cache with no TTL that is valid
@@ -113,19 +109,6 @@ def DNSLookup_pydns(name, qtype, tcpfallback=True, timeout=30):
except IOError, x: except IOError, x:
raise DNS.DNSError, 'DNS: ' + str(x) raise DNS.DNSError, 'DNS: ' + str(x)
def install_pydns():
import DNS # http://pydns.sourceforge.net
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
DNS.DiscoverNameServers() # Fails on Mac OS X? Add domain to /etc/resolv.conf
DNSLookup = DNSLookup_pydns
def DNSLookup_dnspython(name,qtype,tcpfallback=True,timeout=30): def DNSLookup_dnspython(name,qtype,tcpfallback=True,timeout=30):
retVal = [] retVal = []
try: try:
@@ -146,7 +129,8 @@ def DNSLookup_dnspython(name,qtype,tcpfallback=True,timeout=30):
pass pass
return retVal return retVal
def install_dnspython(): try:
# prefer dnspython (the more complete library)
import dns import dns
import dns.resolver # http://www.dnspython.org import dns.resolver # http://www.dnspython.org
import dns.exception import dns.exception
@@ -157,6 +141,19 @@ def install_dnspython():
dns.rdatatype._by_text['SPF'] = dns.rdatatype.SPF dns.rdatatype._by_text['SPF'] = dns.rdatatype.SPF
DNSLookup = DNSLookup_dnspython DNSLookup = DNSLookup_dnspython
except:
import DNS # http://pydns.sourceforge.net
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
if __name__ == '__main__': if __name__ == '__main__':
import sys import sys