Allows to query different classes. Closes #17

master
Stephane Bortzmeyer 10 years ago
parent 703ec94ddd
commit eb7561780d

@ -27,6 +27,9 @@ class Servfail(Exception):
class UnknownRRtype(Exception):
pass
class UnknownClass(Exception):
pass
class UnknownError(Exception):
def __init__(self, value):
self.value = value
@ -60,24 +63,29 @@ class Resolver():
self.nameservers = self.original_nameservers
self.do = self.original_do
def query(self, name, type, tcp=False, cd=False):
def query(self, name, type, klass='IN', tcp=False, cd=False):
""" The returned value is a DNSLG.Answer """
if len(self.nameservers) == 0:
raise NoNameservers()
for ns in self.nameservers:
try:
message = dns.message.make_query(name, type,
message = dns.message.make_query(name, type, rdclass=klass,
use_edns=self.edns, payload=self.payload,
want_dnssec=self.do)
except TypeError: # Old DNS Python... Code here just as long as it lingers in some places
try:
message = dns.message.make_query(name, type, use_edns=self.edns,
message = dns.message.make_query(name, type, rdclass=klass,
use_edns=self.edns,
want_dnssec=self.do)
except dns.rdatatype.UnknownRdatatype:
raise UnknownRRtype()
except dns.rdataclass.UnknownRdataclass:
raise UnknownClass()
message.payload = self.payload
except dns.rdatatype.UnknownRdatatype:
raise UnknownRRtype()
except dns.rdataclass.UnknownRdataclass:
raise UnknownClass()
if cd:
message.flags |= dns.flags.CD
done = False

@ -119,7 +119,6 @@ Disallow: /
reverse=False):
""" path must starts with a /, then the domain name then an
(optional) / followed by the QTYPE """
# TODO: document and implement the query class
if not path.startswith('/'):
raise Exception("Internal error: no / at the beginning of %s" % path)
plaintype = 'text/plain; charset=%s' % self.encoding
@ -189,21 +188,27 @@ Disallow: /
qtype = 'PTR'
else:
domain = args
qtype = 'A'
qtype = 'ADDR'
else:
if reverse:
domain = str(dns.reversename.from_address(args[:slashpos]))
else:
domain = args[:slashpos]
requested_qtype = args[slashpos+1:].upper()
nextslashpos = args.find('/', slashpos+1)
if nextslashpos == -1:
requested_qtype = args[slashpos+1:].upper()
qclass = 'IN'
else:
requested_qtype = args[slashpos+1:nextslashpos].upper()
qclass = args[nextslashpos+1:].upper()
# We do not test if the QTYPE exists. If it doesn't
# dnspython will raise an exception. The formatter will
# have to deal with the various records.
if requested_qtype == "":
if reverse:
type = 'PTR'
qtype = 'PTR'
else:
qtype = 'A'
qtype = 'ADDR'
else:
qtype = requested_qtype
if reverse and qtype != 'PTR':
@ -251,7 +256,7 @@ Disallow: /
self.resolver.set_nameservers([alt_resolver,])
query_start = datetime.now()
if qtype != "ADDR":
answer = self.resolver.query(qdomain, qtype, tcp=tcp, cd=cd)
answer = self.resolver.query(qdomain, qtype, qclass, tcp=tcp, cd=cd)
else:
try:
answer = self.resolver.query(qdomain, "A", tcp=tcp, cd=cd)
@ -282,6 +287,11 @@ Disallow: /
output = output.encode(self.encoding)
send_response(start_response, '400 Unknown record type', output,
plaintype)
except Resolver.UnknownClass:
output = "Class %s does not exist\n" % qclass
output = output.encode(self.encoding)
send_response(start_response, '400 Unknown class', output,
plaintype)
except Resolver.NoSuchDomainName:
output = "Domain %s does not exist\n" % domain
output = output.encode(self.encoding)

@ -44,12 +44,12 @@ The major usage of this program is through REST requests
do not know REST, do not worry; basically, it means we use ordinary
HTTP requests). If the program is installed at
<http://dns.example.net/>, the URL for the requests will be
<http://dns.example.net/$DOMAIN[/$TYPE]> where DOMAIN is the domain
name and TYPE a DNS record type (such as AAAA or MX).
<http://dns.example.net/$DOMAIN[/$TYPE][/$CLASS]> where DOMAIN is the
domain name and TYPE a DNS record type (such as AAAA or MX).
More formally, following the language of URI Templates (RFC 6570), the
URLs of this service are
<http://dns.example.net/{+domain}/{querytype}{?format,server,buffersize,dodnssec,tcp,reverse}>
<http://dns.example.net/{+domain}/{querytype}/{queryclass}{?format,server,buffersize,dodnssec,tcp,reverse}>
There is a non-standard pseudo-querytype ADDR to request both A and
AAAA, specially for the links in the HTML output.

@ -6,7 +6,7 @@ use_setuptools()
from setuptools import setup
setup(name='DNS-LG',
version='2013020201',
version='2013020202',
description='DNS Looking Glass',
license='BSD',
author='Stephane Bortzmeyer',

Loading…
Cancel
Save