Пример #1
0
 def testAFSDB(self):
     """Test DNS 'AFSDB' record queries"""
     return self.namesTest(
         self.resolver.lookupAFSDatabase('test-domain.com'), [
             dns.Record_AFSDB(
                 subtype=1, hostname='afsdb.test-domain.com', ttl=19283784)
         ])
Пример #2
0
 def test_afsdb(self):
     """
     The repr of a L{dns.Record_AFSDB} instance includes the subtype,
     hostname, and TTL of the record.
     """
     self.assertEqual(repr(dns.Record_AFSDB(3, 'example.org', 5)),
                      "<AFSDB subtype=3 hostname=example.org ttl=5>")
Пример #3
0
 def test_afsdb(self):
     """
     Two L{dns.Record_AFSDB} instances compare equal if and only if they
     have the same subtype, hostname, and ttl.
     """
     # Vary the subtype
     self._equalityTest(dns.Record_AFSDB(1, 'example.com', 2),
                        dns.Record_AFSDB(1, 'example.com', 2),
                        dns.Record_AFSDB(2, 'example.com', 2))
     # Vary the hostname
     self._equalityTest(dns.Record_AFSDB(1, 'example.com', 2),
                        dns.Record_AFSDB(1, 'example.com', 2),
                        dns.Record_AFSDB(1, 'example.org', 2))
     # Vary the ttl
     self._equalityTest(dns.Record_AFSDB(1, 'example.com', 2),
                        dns.Record_AFSDB(1, 'example.com', 2),
                        dns.Record_AFSDB(1, 'example.com', 3))
Пример #4
0
     dns.Record_SPF('v=spf1 +mx a:\0colo',
                    '.example.com/28 -all not valid'),
     dns.Record_MX(10, 'host.test-domain.com'),
     dns.Record_HINFO(os='Linux', cpu='A Fast One, Dontcha know'),
     dns.Record_CNAME('canonical.name.com'),
     dns.Record_MB('mailbox.test-domain.com'),
     dns.Record_MG('mail.group.someplace'),
     dns.Record_TXT('A First piece of Text', 'a SecoNd piece'),
     dns.Record_A6(0, 'ABCD::4321', ''),
     dns.Record_A6(12, '0:0069::0', 'some.network.tld'),
     dns.Record_A6(8, '0:5634:1294:AFCB:56AC:48EF:34C3:01FF',
                   'tra.la.la.net'),
     dns.Record_TXT('Some more text, haha!  Yes.  \0  Still here?'),
     dns.Record_MR('mail.redirect.or.whatever'),
     dns.Record_MINFO(rmailbx='r mail box', emailbx='e mail box'),
     dns.Record_AFSDB(subtype=1, hostname='afsdb.test-domain.com'),
     dns.Record_RP(mbox='whatever.i.dunno', txt='some.more.text'),
     dns.Record_WKS('12.54.78.12', socket.IPPROTO_TCP,
                    '\x12\x01\x16\xfe\xc1\x00\x01'),
     dns.Record_NAPTR(100, 10, "u", "sip+E2U",
                      "!^.*$!sip:[email protected]!"),
     dns.Record_AAAA('AF43:5634:1294:AFCB:56AC:48EF:34C3:01FF')
 ],
 'http.tcp.test-domain.com':
 [dns.Record_SRV(257, 16383, 43690, 'some.other.place.fool')],
 'host.test-domain.com': [
     dns.Record_A('123.242.1.5'),
     dns.Record_A('0.255.0.255'),
 ],
 'host-two.test-domain.com': [
     #
Пример #5
0
    def __build_answer(self,
                       query,
                       db_zone,
                       db_record,
                       is_conditional_response=False):
        record = None
        # Calculate the query type (in case it's a request for A but a CNAME is returned).
        query_type = REV_TYPES[db_record.type]
        if query_type == dns.A:
            record = dns.Record_A(address=db_record.property(
                'address', conditional=is_conditional_response),
                                  ttl=db_record.ttl)
        elif query_type == dns.AAAA:
            record = dns.Record_AAAA(address=db_record.property(
                'address', conditional=is_conditional_response),
                                     ttl=db_record.ttl)
        elif query_type == dns.AFSDB:
            record = dns.Record_AFSDB(subtype=int(
                db_record.property('subtype',
                                   conditional=is_conditional_response)),
                                      hostname=db_record.property(
                                          'hostname',
                                          conditional=is_conditional_response))
        elif query_type == dns.CNAME:
            record = dns.Record_CNAME(name=db_record.property(
                'name', conditional=is_conditional_response),
                                      ttl=db_record.ttl)
        elif query_type == dns.DNAME:
            record = dns.Record_DNAME(name=db_record.property(
                'name', conditional=is_conditional_response),
                                      ttl=db_record.ttl)
        elif query_type == dns.HINFO:
            record = dns.Record_HINFO(
                cpu=db_record.property(
                    'cpu', conditional=is_conditional_response).encode(),
                os=db_record.property(
                    'os', conditional=is_conditional_response).encode())
        elif query_type == dns.MX:
            record = dns.Record_MX(preference=int(
                db_record.property('preference',
                                   conditional=is_conditional_response)),
                                   name=db_record.property(
                                       'name',
                                       conditional=is_conditional_response))
        elif query_type == dns.NAPTR:
            record = dns.Record_NAPTR(
                order=int(
                    db_record.property('order',
                                       conditional=is_conditional_response)),
                preference=int(
                    db_record.property('preference',
                                       conditional=is_conditional_response)),
                flags=db_record.property(
                    'flags', conditional=is_conditional_response).encode(),
                service=db_record.property(
                    'service', conditional=is_conditional_response).encode(),
                regexp=db_record.property(
                    'regexp', conditional=is_conditional_response).encode(),
                replacement=db_record.property(
                    'replacement', conditional=is_conditional_response))
        elif query_type == dns.NS:
            record = dns.Record_NS(name=db_record.property(
                'name', conditional=is_conditional_response),
                                   ttl=db_record.ttl)
        elif query_type == dns.PTR:
            record = dns.Record_PTR(name=db_record.property(
                'name', conditional=is_conditional_response),
                                    ttl=db_record.ttl)
        elif query_type == dns.RP:
            record = dns.Record_RP(
                mbox=db_record.property('mbox',
                                        conditional=is_conditional_response),
                txt=db_record.property('txt',
                                       conditional=is_conditional_response))
        elif query_type == dns.SOA:
            record = dns.Record_SOA(
                mname=db_record.property('mname',
                                         conditional=is_conditional_response),
                rname=db_record.property('rname',
                                         conditional=is_conditional_response),
                serial=int(
                    db_record.property('serial',
                                       conditional=is_conditional_response)),
                refresh=int(
                    db_record.property('refresh',
                                       conditional=is_conditional_response)),
                retry=int(
                    db_record.property('retry',
                                       conditional=is_conditional_response)),
                expire=int(
                    db_record.property('expire',
                                       conditional=is_conditional_response)),
                minimum=int(
                    db_record.property('minimum',
                                       conditional=is_conditional_response)))
        elif query_type == dns.SPF:
            record = dns.Record_SPF(
                db_record.property(
                    'data', conditional=is_conditional_response).encode())
        elif query_type == dns.SRV:
            record = dns.Record_SRV(
                priority=int(
                    db_record.property('priority',
                                       conditional=is_conditional_response)),
                port=int(
                    db_record.property('port',
                                       conditional=is_conditional_response)),
                weight=int(
                    db_record.property('weight',
                                       conditional=is_conditional_response)),
                target=db_record.property('target',
                                          conditional=is_conditional_response))
        elif query_type == dns.SSHFP:
            record = dns.Record_SSHFP(
                algorithm=int(
                    db_record.property('algorithm',
                                       conditional=is_conditional_response)),
                fingerprintType=int(
                    db_record.property('fingerprint_type',
                                       conditional=is_conditional_response)),
                fingerprint=db_record.property(
                    'fingerprint',
                    conditional=is_conditional_response).encode())
        elif query_type == dns.TSIG:
            record = dns.Record_TSIG(
                algorithm=db_record.property(
                    'algorithm', conditional=is_conditional_response).encode(),
                timeSigned=int(
                    db_record.property('timesigned',
                                       conditional=is_conditional_response)),
                fudge=int(
                    db_record.property('fudge',
                                       conditional=is_conditional_response)),
                originalID=int(
                    db_record.property('original_id',
                                       conditional=is_conditional_response)),
                MAC=db_record.property(
                    'mac', conditional=is_conditional_response).encode(),
                otherData=db_record.property(
                    'other_data',
                    conditional=is_conditional_response).encode())
        elif query_type == dns.TXT:
            record = dns.Record_TXT(
                db_record.property(
                    'data', conditional=is_conditional_response).encode())
        else:
            pass

        if not record:
            return None

        answer = dns.RRHeader(name=query.name.name,
                              type=query_type,
                              cls=query.cls,
                              ttl=db_record.ttl,
                              payload=record)
        return answer