MCPcopy
hub / github.com/mitmproxy/mitmproxy / dns_request

Method dns_request

mitmproxy/addons/dns_resolver.py:80–99  ·  view source on GitHub ↗
(self, flow: dns.DNSFlow)

Source from the content-addressed store, hash-verified

78 raise MissingNameServers()
79
80 async def dns_request(self, flow: dns.DNSFlow) -> None:
81 if self._should_resolve(flow):
82 all_ip_lookups = (
83 flow.request.query
84 and flow.request.op_code == dns.op_codes.QUERY
85 and flow.request.question
86 and flow.request.question.class_ == dns.classes.IN
87 and flow.request.question.type in (dns.types.A, dns.types.AAAA)
88 )
89 if all_ip_lookups:
90 try:
91 flow.response = await self.resolve(flow.request)
92 except MissingNameServers:
93 flow.error = Error("Cannot resolve, dns_name_servers unknown.")
94 elif name_servers := self.name_servers():
95 # For other records, the best we can do is to forward the query
96 # to an upstream server.
97 flow.server_conn.address = (name_servers[0], 53)
98 else:
99 flow.error = Error("Cannot resolve, dns_name_servers unknown.")
100
101 @staticmethod
102 def _should_resolve(flow: dns.DNSFlow) -> bool:

Callers 1

test_lookupFunction · 0.95

Calls 4

_should_resolveMethod · 0.95
resolveMethod · 0.95
name_serversMethod · 0.95
ErrorClass · 0.90

Tested by 1

test_lookupFunction · 0.76