[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [ooni-probe/master] Support for performing SOA Lookup in ooni.templates.DNST
commit 6083688f28b65f3aeffbb73171ec0cb6790d7c45
Author: Arun Pandian G <arunpandianp@xxxxxxxxx>
Date: Sun Mar 23 09:01:18 2014 +0530
Support for performing SOA Lookup in ooni.templates.DNST
---
ooni/templates/dnst.py | 60 ++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 60 insertions(+)
diff --git a/ooni/templates/dnst.py b/ooni/templates/dnst.py
index 66a6d17..38da177 100644
--- a/ooni/templates/dnst.py
+++ b/ooni/templates/dnst.py
@@ -197,6 +197,66 @@ class DNSTest(NetTestCase):
return d
+ def performSOALookup(self, hostname, dns_server = None):
+ """
+ Performs a SOA lookup and returns the response (name,serial).
+
+ :hostname: is the hostname to perform the NS lookup on
+
+ :dns_server: is the dns_server that should be used for the lookup as a
+ tuple of ip port (ex. ("127.0.0.1", 53))
+ """
+ query = [dns.Query(hostname, dns.SOA, dns.IN)]
+ if dns_server:
+ def gotResponse(message):
+ addrs = []
+ answers = []
+ for answer in message.answers:
+ if answer.type is dns.SOA:
+ addr = (answer.name.name,answer.payload.serial)
+ addrs.append(addr)
+ answers.append(representAnswer(answer))
+
+ DNSTest.addToReport(self, query, resolver=dns_server, query_type='SOA',
+ answers=answers, addrs=addrs)
+ return addrs
+
+ def gotError(failure):
+ failure.trap(gaierror, TimeoutError)
+ DNSTest.addToReport(self, query, resolver=dns_server, query_type='SOA',
+ failure=failure)
+ return failure
+
+ resolver = Resolver(servers=[dns_server])
+ d = resolver.queryUDP(query, timeout=self.queryTimeout)
+ d.addCallback(gotResponse)
+ d.addErrback(gotError)
+ else:
+ def gotResponse(message):
+ addrs = []
+ answers = []
+ for answer in message[0]:
+ if answer.type is dns.SOA:
+ addr = (answer.name.name,answer.payload.serial)
+ addrs.append(addr)
+ answers.append(representAnswer(answer))
+
+ DNSTest.addToReport(self, query, resolver=dns_server, query_type='SOA',
+ answers=answers, addrs=addrs)
+ return addrs
+
+ def gotError(failure):
+ failure.trap(gaierror, TimeoutError)
+ DNSTest.addToReport(self, query, resolver=dns_server, query_type='SOA',
+ failure=failure)
+ return failure
+
+ d = client.lookupAuthority(hostname)
+ d.addCallback(gotResponse)
+ d.addErrback(gotError)
+
+ return d
+
def addToReport(self, query, resolver=None, query_type=None,
answers=None, name=None, addrs=None, failure=None):
log.debug("Adding %s to report)" % query)
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits