a MeE@sdZddlZddlZddlmZmZmZmZmZddl Z ddl Z ddl Z ddl Z ddlZ ddlZ ddlZ ddlZ ddlZ ddlmZmZmZmZe jjZe jjZGddde jjZdaeddd Z ddd d Z!e j"j#e j$j%d dd ddddf ee j&j'e(fee j"j)e(fee j$j*e(fe+ee(e+e,ee-ee+ee j.j/e jj0d ddZ1e(eee jj0dddZ2ej3fee j&j'e(fe,ee jj4dddZ5ee j&j'e(fe j&j'dddZ6d(e-ddddZ7e j$j%d ddfee j&j'e(fe j$j*e+eeee j.j/e j&j'ddd Z8d!ej3dfee j&j'e(fe,e,eeed"d#d$Z9e j"j#e j$j%d dd ddddd!ej3df ee j&j'e(fee j&j'e(fee j"j)e(fee j$j*e(fe+ee(e+e,ee-ee+ee j.j/e,e,eee jj0d%d&d'Z:dS))Asynchronous DNS stub resolver.N)AnyDictListOptionalUnion)NXDOMAINNoAnswer NoRootSOA NotAbsolutec @seZdZdZejjejjdddddddf e ej j e fe ejj e fe ejje feee eeeeeeeejjejjd ddZe eeejjd d d Zejfe ej j e feeejjd d dZe ej j e fej j dddZdeddddZdS)ResolverrFNTr qnamerdtyperdclasstcpsourceraise_on_no_answer source_portlifetimesearchbackendreturnc  stj||||||| } | s&tj} t} | \} }|durF|Sd}|s.| \}}}|rp| |IdH| | || j }z |j | ||||| dIdH}Wn@t y}z(| d|\}}WYd}~qJWYd}~n d}~00| |d\}}|durJ|SqJq.dS)aQuery nameservers asynchronously to find the answer to the question. *backend*, a ``dns.asyncbackend.Backend``, or ``None``. If ``None``, the default, then dnspython will use the default backend. See :py:func:`dns.resolver.Resolver.resolve()` for the documentation of the other parameters, exceptions, and return type of this method. NF)timeoutrrZmax_sizer)dnsresolverZ _Resolution asyncbackendZget_default_backendtimeZ next_requestZnext_nameserversleep_compute_timeouterrorsZ async_query ExceptionZ query_result)selfrrrrrrrrrrZ resolutionstartZrequestanswerZdone nameserverZbackoffrresponseex_r)5/usr/lib/python3.9/site-packages/dns/asyncresolver.pyresolve-s<  "zResolver.resolveipaddrargskwargsrcsLi}||tjj|d<tjj|d<|jtj|g|Ri|IdHS)aUse an asynchronous resolver to run a reverse query for PTR records. This utilizes the resolve() method to perform a PTR lookup on the specified IP address. *ipaddr*, a ``str``, the IPv4 or IPv6 address you want to get the PTR record for. All other arguments that can be passed to the resolve() function except for rdtype and rdclass are also supported by this function. rrN) updater rdatatypeZPTR rdataclassINr+Z reversenameZ from_address)r"r-r.r/modified_kwargsr)r)r*resolve_addressns    zResolver.resolve_addressnamefamilyr/rc sXi}|||ddtjj|d<|tjkr^|j|tjj fi|IdH}tj j j |dS|tj kr|j|tjjfi|IdH}tj j j |dS|tjkrtd||dd}|d d}t} |j|tjjfd || |d |IdH}|j}|j|tjj fd || |d |IdH}tj j j ||| d } | sTt|jd | S)aUse an asynchronous resolver to query for address records. This utilizes the resolve() method to perform A and/or AAAA lookups on the specified name. *qname*, a ``dns.name.Name`` or ``str``, the name to resolve. *family*, an ``int``, the address family. If socket.AF_UNSPEC (the default), both A and AAAA records will be retrieved. All other arguments that can be passed to the resolve() function except for rdtype and rdclass are also supported by this function. rNr)v4)v6zunknown address family rTrF)rr)r:r9Z add_empty)r&)r0poprr2r3socketZAF_INETr+r1Ar HostAnswersZmakeZAF_INET6ZAAAA AF_UNSPECNotImplementedErrorrrrr r&) r"r7r8r/r4r9r:rrr#answersr)r)r* resolve_namesP             zResolver.resolve_namer7rc sRz|j|ddIdH}|j}Wn.tjjyL}z|j}WYd}~n d}~00|S)aDetermine the canonical name of *name*. The canonical name is the name the resolver uses for queries after all CNAME and DNAME renamings have been applied. *name*, a ``dns.name.Name`` or ``str``, the query name. This method can raise any exception that ``resolve()`` can raise, other than ``dns.resolver.NoAnswer`` and ``dns.resolver.NXDOMAIN``. Returns a ``dns.name.Name``. F)rN)r+canonical_namerrr)r"r7r$rDer)r)r*rDs  zResolver.canonical_name@)rrcstz\t|}|jtjjd|dIdH}tj|}tj||IdH}t|dkrZ||_ Wnt ynYn0dS)aTry to update the resolver's nameservers using Discovery of Designated Resolvers (DDR). If successful, the resolver will subsequently use DNS-over-HTTPS or DNS-over-TLS for future queries. *lifetime*, a float, is the maximum time to spend attempting DDR. The default is 5 seconds. If the SVCB query is successful and results in a non-empty list of nameservers, then the resolver's nameservers are set to the returned servers in priority order. The current implementation does not use any address hints from the SVCB record, nor does it resolve addresses for the SCVB target name, rather it assumes that the bootstrap nameserver will always be one of the addresses and uses it. A future revision to the code may offer fuller support. The code verifies that the bootstrap nameserver is in the Subject Alternative Name field of the TLS certficate. Zsvcb)rNr) rr+rZ_ddrZ_local_resolver_namequeryZ _remainingZ_get_nameservers_asynclen nameserversr!)r"rZ expirationr$rrIr)r)r*try_ddrs      zResolver.try_ddr)rF) __name__ __module__ __qualname____doc__rr1r=r2r3rr7Namestr RdataType RdataClassboolrintfloatrBackendrAnswerr+rr5r<r?r>rBrDrJr)r)r)r*r *sF  B  E r )rcCstdurttS)zDGet the default asynchronous resolver, initializing it if necessary.N)default_resolverreset_default_resolverr)r)r)r*get_default_resolversrZcCs tadS)zRe-initialize default asynchronous resolver. Note that the resolver configuration (i.e. /etc/resolv.conf on UNIX systems) will be re-read immediately. N)r rXr)r)r)r*rYsrYFTr c s$t|||||||||| IdHS)a Query nameservers asynchronously to find the answer to the question. This is a convenience function that uses the default resolver object to make the query. See :py:func:`dns.asyncresolver.Resolver.resolve` for more information on the parameters. N)rZr+) rrrrrrrrrrr)r)r*r+sr+r,cs tj|g|Ri|IdHS)zUse a resolver to run a reverse query for PTR records. See :py:func:`dns.asyncresolver.Resolver.resolve_address` for more information on the parameters. N)rZr5)r-r.r/r)r)r*r5=s r5r6cstj||fi|IdHS)zUse a resolver to asynchronously query for address records. See :py:func:`dns.asyncresolver.Resolver.resolve_name` for more information on the parameters. N)rZrB)r7r8r/r)r)r*rBIs rBrCcst|IdHS)zDetermine the canonical name of *name*. See :py:func:`dns.resolver.Resolver.canonical_name` for more information on the parameters and possible exceptions. N)rZrD)r7r)r)r*rDUsrDrF)rrcst|IdHS)aTry to update the default resolver's nameservers using Discovery of Designated Resolvers (DDR). If successful, the resolver will subsequently use DNS-over-HTTPS or DNS-over-TLS for future queries. See :py:func:`dns.resolver.Resolver.try_ddr` for more information. N)rZrJ)rr)r)r*rJ_srJ)r7rrrrrc st|trtj|tjj}|dur*t}|s:t|z4|j |tj j |||dIdH}|j j|krl|WSWnt tfyYn0z |}Wq:tjjytYq:0q:dS)zFind the name of the zone which contains the specified name. See :py:func:`dns.resolver.Resolver.zone_for_name` for more information on the parameters and possible exceptions. N)r) isinstancerPrr7Z from_textrootrZ is_absoluter r+r1ZSOAZrrsetrr parentZNoParentr )r7rrrrr$r)r)r* zone_for_nameis$     r_5)whereportr8rrcs|durt}g}t|tr>tj|r>|tj||n4| ||IdH}| D]}|tj||qXtj j dd}||_ |S)aMake a stub resolver using the specified destination as the full resolver. *where*, a ``dns.name.Name`` or ``str`` the domain name or IP address of the full resolver. *port*, an ``int``, the port to use. If not specified, the default is 53. *family*, an ``int``, the address family to use. This parameter is used if *where* is not an address. The default is ``socket.AF_UNSPEC`` in which case the first address returned by ``resolve_name()`` will be used, otherwise the first address of the specified family will be used. *resolver*, a ``dns.asyncresolver.Resolver`` or ``None``, the resolver to use for resolution of hostnames. If not specified, the default resolver will be used. Returns a ``dns.resolver.Resolver`` or raises an exception. NF)Z configure)rZr[rPrZinetZ is_addressappendr%ZDo53NameserverrBZ addressesZ asyncresolverr rI)rarbr8rrIrAZaddressresr)r)r*make_resolver_ats re)rarrrrrrrrrrrbr8rrc s6t|| | | IdH}|||||||||| | IdHS)aQuery nameservers to find the answer to the question. This is a convenience function that calls ``dns.asyncresolver.make_resolver_at()`` to make a resolver, and then uses it to resolve the query. See ``dns.asyncresolver.Resolver.resolve`` for more information on the resolution parameters, and ``dns.asyncresolver.make_resolver_at`` for information about the resolver parameters *where*, *port*, *family*, and *resolver*. If making more than one query, it is more efficient to call ``dns.asyncresolver.make_resolver_at()`` and then use that resolver for the queries instead of calling ``resolve_at()`` multiple times. N)rer+)rarrrrrrrrrrrbr8rrdr)r)r* resolve_atsrf)rF);rNr<rtypingrrrrrZdns._ddrrZdns.asyncbackendZdns.asyncqueryZ dns.exceptionZdns.nameZ dns.queryZdns.rdataclassZ dns.rdatatypeZ dns.resolverrr r r Z asyncqueryZudpZ_udprZ_tcprZ BaseResolverr rXrZrYr1r=r2r3r7rOrPrQrRrSrTrUrrVrWr+r5r?r>rBrDrJr_rerfr)r)r)r*s[   $     & (