ans.py revision 1.1 1 """
2 Copyright (C) Internet Systems Consortium, Inc. ("ISC")
3
4 SPDX-License-Identifier: MPL-2.0
5
6 This Source Code Form is subject to the terms of the Mozilla Public
7 License, v. 2.0. If a copy of the MPL was not distributed with this
8 file, you can obtain one at https://mozilla.org/MPL/2.0/.
9
10 See the COPYRIGHT file distributed with this work for additional
11 information regarding copyright ownership.
12 """
13
14 from collections.abc import AsyncGenerator
15
16 import dns.rcode
17 import dns.rdatatype
18 import dns.rrset
19
20 from isctest.asyncserver import (
21 AsyncDnsServer,
22 DnsResponseSend,
23 QueryContext,
24 ResponseAction,
25 ResponseHandler,
26 )
27
28
29 class AttackerAuthority(ResponseHandler):
30 async def get_responses(
31 self, qctx: QueryContext
32 ) -> AsyncGenerator[ResponseAction, None]:
33 if qctx.qtype == dns.rdatatype.A:
34 qctx.response.answer.append(
35 dns.rrset.from_text(
36 qctx.qname, 300, qctx.qclass, dns.rdatatype.A, "6.6.6.6"
37 )
38 )
39
40 yield DnsResponseSend(qctx.response)
41
42
43 def main() -> None:
44 server = AsyncDnsServer(default_aa=True, default_rcode=dns.rcode.NOERROR)
45 server.install_response_handler(AttackerAuthority())
46 server.run()
47
48
49 if __name__ == "__main__":
50 main()
51