U mfE@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  s tj||||||| } | s&tj} t} | \} }|dk rF|S| dk sRtd}|s.| \}}}|r|| |IdH| | || j }z |j | ||||| dIdH}Wn:t k r}z| d|\}}WYqVW5d}~XYnX| |d\}}|dk rV|SqVq.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)timeoutrrmax_sizer)dnsresolverZ _Resolution asyncbackendZget_default_backendtimeZ next_requestAssertionErrorZnext_nameserversleep_compute_timeouterrorsZ async_query ExceptionZ query_result)selfrrrrrrrrrr resolutionstartrequestanswerdone nameserverbackoffrresponseex_r/?/opt/hc_python/lib/python3.8/site-packages/dns/asyncresolver.pyresolve-sJ   zResolver.resolveipaddrargskwargsrcsFi}||tjj|d<tjj|d<|jtj|f||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 rdataclassINr1Z reversenameZ from_address)r$r3r4r5modified_kwargsr/r/r0resolve_addressns    zResolver.resolve_addressnamefamilyr5rc sPi}|||ddtjj|d<|tjkrZ|j|tjj f|IdH}tj j j |dS|tj kr|j|tjjf|IdH}tj j j |dS|tjkrtd||dd}|d d}t} |j|tjjfd || |d |IdH}|j}|j|tjj fd || |d |IdH}tj j j ||| d } | sLt|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@r?Z add_empty)r,)r6poprr8r9socketAF_INETr1r7Ar HostAnswersmakeAF_INET6ZAAAA AF_UNSPECNotImplementedErrorrr!rr r,) r$r=r>r5r:r?r@rrr&answersr/r/r0 resolve_namesT             zResolver.resolve_namer=rc sPz|j|ddIdH}|j}Wn,tjjk rJ}z |j}W5d}~XYnX|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)r1canonical_namerrr)r$r=r(rMer/r/r0rMs  zResolver.canonical_name@)rrcsvz\t|}|jtjjd|dIdH}tj|}tj||IdH}t|dkrZ||_ Wnt k rpYnXdS)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) rr1rZ_ddrZ_local_resolver_namequeryZ _remainingZ_get_nameservers_asynclen nameserversr#)r$rZ expirationr(rrRr/r/r0try_ddrs     zResolver.try_ddr)rO) __name__ __module__ __qualname____doc__rr7rDr8r9rr=Namestr RdataType RdataClassboolrintfloatrBackendrAnswerr1rr;rBrHrErKrMrSr/r/r/r0r *sJ  B  E r )rcCstdkrttdk sttS)zDGet the default asynchronous resolver, initializing it if necessary.N)default_resolverreset_default_resolverrr/r/r/r0get_default_resolvers rccCs 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 rar/r/r/r0rbsrbFTr 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)rcr1) rrrrrrrrrrr/r/r0r1sr1r2cstj|f||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)rcr;)r3r4r5r/r/r0r;=s r;r<cstj||f|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)rcrK)r=r>r5r/r/r0rKIs rKrLcst|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)rcrM)r=r/r/r0rMUsrMrO)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)rcrS)rr/r/r0rS_srS)r=rrrrrc st|trtj|tjj}|dkr*t}|s:t|zB|j |tj j |||dIdH}|j dk sht |j j|krz|WSWnttfk rYnXz |}Wq:tjjk rtYq:Xq: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) isinstancerYrr=Z from_textrootrc is_absoluter r1r7ZSOAZrrsetrrr parentZNoParentr )r=rrrrr(r/r/r0 zone_for_nameis.     rh5)whereportr>rrcs|dkrt}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) configure)rcrdrYrZinetZ is_addressappendr*ZDo53NameserverrK addressesZ asyncresolverr rR)rjrkr>rrRrJaddressresr/r/r0make_resolver_ats rq)rjrrrrrrrrrrrkr>rrc 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)rqr1)rjrrrrrrrrrrrkr>rrpr/r/r0 resolve_atsrr)rO);rWrBrtypingrrrrrZdns._ddrrZdns.asyncbackendZdns.asyncqueryZ dns.exceptionZdns.nameZ dns.queryZdns.rdataclassZ dns.rdatatypeZ dns.resolverrr r r Z asyncqueryZudpZ_udprZ_tcpr BaseResolverr rarcrbr7rDr8r9r=rXrYrZr[r\r]r^rr_r`r1r;rHrErKrMrSrhrqrrr/r/r/r0s[   $     & (