o
    hI~                  #   @   s  d Z ddlZddlZddlZddlZddlZddlZddlZddl	m
Z
mZmZmZmZ ddlZddlZddlZddlZddlZddlZddlZddlZddlZddlZddlmZ ddlmZmZmZm Z m!Z!m"Z"m#Z#m$Z$m%Z%m&Z&m'Z' zddl(Z(W n e)y   ddl*m+Z( Y nw e&rddl,Z,ej-j.Z/dd Z0dYdd	Z1	dYd
ej2j3dej4j5e6B de
de7dB dee8e7f f
ddZ9										dZd
ej2j3de
dB de7dB de:de:deej;j<ej=j>f dB de6dB de:de:de:dej4j5dB de
fddZ?											d[dej4j5de@d e7dB d!e8d"e@dB d#e8de:de:de:de:d
ej2j3dB d$ej2jAdB de:dej4j5fd%d&ZB											d\dej4j5de@d e7dB d!e8d"e@dB d#e8de:de:de:d'ej2j3dB d(ej2jCdB d$ej2jAdB de:deej4j5e:f fd)d*ZD	dYd
ej2jCdej4j5e6B de7dB dee8e7f fd+d,ZEd-d. ZF					d]d
ej2jCde7dB de:deej;j<ej=j>f dB de6dB de:deej4j5e7f fd/d0ZG								d^dej4j5de@d e7dB d!e8d"e@dB d#e8de:de:d
ej2jCdB d$ej2jAdB dej4j5fd1d2ZH		3									4d_dej4j5de@d e7dB d!e8d"e@dB d#e8de:de:d
ej2jCdB d$ej2jAdB d5e(jIdB d6e@dB d7e:e@B dej4j5fd8d9ZJd:ed; dd;fd<d=ZKdd>dddddd?d4d4ddejLejMfdej4j5de@d e7dB d!e8d"e@dB d#e8de:de:d@edA dBe@dCe:d7e:e@B e(jIB dDe@dB d:ed; dEe8dFedej4j5f"dGdHZN		>					4		4	d`dej4j5de@dIe@d e7dB d!e8d"e@dB d#e8de:de:d7e:e@B e(jIB d$ej2jAdB dCe:dJejOjPdB dej4j5fdKdLZQ		3						4			dadej4j5de@d e7dB d!e8d"e@dB d#e8de:de:dJejOjPdB d7e:e@B d$ej2jAdB dMe@dB d6e@dB dej4j5fdNdOZOdPejRjSdQej2jTdej4j5dRe8dB d e7dB de7de
fdSdTZUdddddde!jVdfde@dPejRjSdej4j5dB d!e8d e7dB dUe7dB d"e@dB d#e8dVe!d$ej2jAdB ddfdWdXZWdS )bzTalk to a DNS server.    N)AnyDictOptionalTuplecast)NullContext)BadResponseHTTPVersionNoDOHNoDOQUDPMode_check_status_compute_times_matches_destination
_remaininghave_dohmake_ssl_contextc                 C   sV   |s|r)|d u r%| t jkrd}||fS | t jkrd}||fS td|  ||fS d S )Nz0.0.0.0z::zunknown address family )socketAF_INETAF_INET6NotImplementedError)afaddressport r   P/var/www/html/pro-man-master/venv/lib/python3.10/site-packages/dns/asyncquery.py_source_tupleB   s   

r   c                 C   s&   | d ur|s
t   }t| | dS d S Nr   )timemax)
expirationnowr   r   r   _timeoutR   s
   r"   sockwhatdestinationr    returnc                    sB   t |tjjr| }t }| ||t||I dH }||fS )a  Send a DNS message to the specified UDP socket.

    *sock*, a ``dns.asyncbackend.DatagramSocket``.

    *what*, a ``bytes`` or ``dns.message.Message``, the message to send.

    *destination*, a destination tuple appropriate for the address family
    of the socket, specifying where to send the query.

    *expiration*, a ``float`` or ``None``, the absolute time at which
    a timeout exception should be raised.  If ``None``, no timeout will
    occur.  The expiration value is meaningless for the asyncio backend, as
    asyncio's transport sendto() never blocks.

    Returns an ``(int, float)`` tuple of bytes sent and the sent time.
    N)
isinstancednsmessageMessageto_wirer   sendtor"   )r#   r$   r%   r    	sent_timenr   r   r   send_udp[   s   r/   F    ignore_unexpectedone_rr_per_rrsetkeyringrequest_macignore_trailingraise_on_truncationignore_errorsqueryc              
      s   d}	 |  dt|I dH \}}t| j|||sqt }ztjj||||||d}W n- tjjyN } z|	rI|
durI|
	| sIW Y d}~q d}~w t
yY   |	rXY q w |	rf|
durf|
	|sfq|||fS )aj  Read a DNS message from a UDP socket.

    *sock*, a ``dns.asyncbackend.DatagramSocket``.

    See :py:func:`dns.query.receive_udp()` for the documentation of the other
    parameters, and exceptions.

    Returns a ``(dns.message.Message, float, tuple)`` tuple of the received message, the
    received time, and the address where the message arrived from.
    r0   T  N)r3   r4   r2   r5   r6   )recvfromr"   r   familyr   r(   r)   	from_wire	Truncatedis_response	Exception)r#   r%   r    r1   r2   r3   r4   r5   r6   r7   r8   wirefrom_addressreceived_timerer   r   r   receive_udpy   sF   


rE   5   qwheretimeoutr   sourcesource_portbackendc                    s$  |   }t|\}}tj|}t||f|}|
rt|
}n%|s&tj }t	|||}|
 r5||f}nd}||tjd||I dH }|4 I dH ;}t||||I dH  t|||||| j| j||	|| I dH \}}}|| |_|sy| |syt|W  d  I dH  S 1 I dH sw   Y  dS )aF  Return the response obtained after sending a query via UDP.

    *sock*, a ``dns.asyncbackend.DatagramSocket``, or ``None``,
    the socket to use for the query.  If ``None``, the default, a
    socket is created.  Note that if a socket is provided, the
    *source*, *source_port*, and *backend* are ignored.

    *backend*, a ``dns.asyncbackend.Backend``, or ``None``.  If ``None``,
    the default, then dnspython will use the default backend.

    See :py:func:`dns.query.udp()` for the documentation of the other
    parameters, exceptions, and return type of this method.
    Nr   )r+   r   r(   inetaf_for_address_lltupler   asyncbackendget_default_backendr   datagram_connection_requiredmake_socketr   
SOCK_DGRAMr/   rE   r3   macr   r>   r   )rG   rH   rI   r   rJ   rK   r1   r2   r5   r6   r#   rL   r7   r@   
begin_timer    r   r%   cmstupledtuplesrC   rB   _r   r   r   udp   sD   



0r\   udp_socktcp_sockc                    sr   zt | ||||||||d|	||I dH }|dfW S  tjjy8   t| ||||||||
|
I dH }|df Y S w )a  Return the response to the query, trying UDP first and falling back
    to TCP if UDP results in a truncated response.

    *udp_sock*, a ``dns.asyncbackend.DatagramSocket``, or ``None``,
    the socket to use for the UDP query.  If ``None``, the default, a
    socket is created.  Note that if a socket is provided the *source*,
    *source_port*, and *backend* are ignored for the UDP query.

    *tcp_sock*, a ``dns.asyncbackend.StreamSocket``, or ``None``, the
    socket to use for the TCP query.  If ``None``, the default, a
    socket is created.  Note that if a socket is provided *where*,
    *source*, *source_port*, and *backend*  are ignored for the TCP query.

    *backend*, a ``dns.asyncbackend.Backend``, or ``None``.  If ``None``,
    the default, then dnspython will use the default backend.

    See :py:func:`dns.query.udp_with_fallback()` for the documentation
    of the other parameters, exceptions, and return type of this
    method.
    TNF)r\   r(   r)   r=   tcp)rG   rH   rI   r   rJ   rK   r1   r2   r5   r]   r^   rL   r7   responser   r   r   udp_with_fallback   sB   #


ra   c                    s^   t |tjjr|jdd}n
t|dd| }t }| |t	||I dH  t||fS )zSend a DNS message to the specified TCP socket.

    *sock*, a ``dns.asyncbackend.StreamSocket``.

    See :py:func:`dns.query.send_tcp()` for the documentation of the other
    parameters, exceptions, and return type of this method.
    T)prepend_length   bigN)
r'   r(   r)   r*   r+   lento_bytesr   sendallr"   )r#   r$   r    tcpmsgr-   r   r   r   send_tcp<  s   ri   c                    sT   d}|dkr(|  |t|I dH }|dkrtd|t| }|| }|dks|S )z|Read the specified number of bytes from stream.  Keep trying until we
    either get the desired amount, or we hit EOF.
    r0   r   NEOF)recvr"   EOFErrorre   )r#   countr    rZ   r.   r   r   r   _read_exactlyU  s   rn   c                    sZ   t | d|I dH }td|\}t | ||I dH }t }	tjj|||||d}
|
|	fS )zRead a DNS message from a TCP socket.

    *sock*, a ``dns.asyncbackend.StreamSocket``.

    See :py:func:`dns.query.receive_tcp()` for the documentation of the other
    parameters, exceptions, and return type of this method.
    rc   N!Hr3   r4   r2   r5   )rn   structunpackr   r(   r)   r<   )r#   r    r2   r3   r4   r5   ldatalr@   rB   rC   r   r   r   receive_tcpc  s   ru   c
              	      s  |   }
t|\}}|r| I dH  t|}n%tj|}t|||}||f}|	s0tj	 }	|	
|tjd|||I dH }|4 I dH 2}t||
|I dH  t|||| j| j|I dH \}}|| |_| |sjt|W  d  I dH  S 1 I dH s|w   Y  dS )aO  Return the response obtained after sending a query via TCP.

    *sock*, a ``dns.asyncbacket.StreamSocket``, or ``None``, the
    socket to use for the query.  If ``None``, the default, a socket
    is created.  Note that if a socket is provided
    *where*, *port*, *source*, *source_port*, and *backend* are ignored.

    *backend*, a ``dns.asyncbackend.Backend``, or ``None``.  If ``None``,
    the default, then dnspython will use the default backend.

    See :py:func:`dns.query.tcp()` for the documentation of the other
    parameters, exceptions, and return type of this method.
    Nr   )r+   r   getpeernamer   r(   rM   rN   r   rP   rQ   rS   r   SOCK_STREAMri   ru   r3   rU   r   r>   r   )rG   rH   rI   r   rJ   rK   r2   r5   r#   rL   r@   rV   r    rW   r   rX   rY   rZ   rC   rB   r   r   r   r_     s:   




0r_   U  Tssl_contextserver_hostnameverifyc                    s   t |\}}|rt|}n4|
du rt||dudg}
tj|}t|||}||f}|	s2tj }	|		|t
jd||||
|I dH }|4 I dH *}t|}t| |||||||||	
I dH }t }|| |_|W  d  I dH  S 1 I dH sxw   Y  dS )a  Return the response obtained after sending a query via TLS.

    *sock*, an ``asyncbackend.StreamSocket``, or ``None``, the socket
    to use for the query.  If ``None``, the default, a socket is
    created.  Note that if a socket is provided, it must be a
    connected SSL stream socket, and *where*, *port*,
    *source*, *source_port*, *backend*, *ssl_context*, and *server_hostname*
    are ignored.

    *backend*, a ``dns.asyncbackend.Backend``, or ``None``.  If ``None``,
    the default, then dnspython will use the default backend.

    See :py:func:`dns.query.tls()` for the documentation of the other
    parameters, exceptions, and return type of this method.
    Ndotr   )r   r   r   r(   rM   rN   r   rP   rQ   rS   r   rw   r"   r_   r   )rG   rH   rI   r   rJ   rK   r2   r5   r#   rL   ry   rz   r{   rV   r    rW   r   rX   rY   rZ   r`   end_timer   r   r   tls  sN   





0r~   resolverzdns.asyncresolver.Resolverc                 C   s   | d u rdd l }|j } | S r   )dns.asyncresolverasyncresolverResolver)r   r(   r   r   r   _maybe_get_resolver  s   
r     z
/dns-queryclientz.httpx.AsyncClient|dns.quic.AsyncQuicConnectionpathpostbootstrap_addressr;   http_versionc           "         sf  zt j|}W n ty   d}Y nw |}|dur@t j|r@|tjkr1d| d| |	 }n|tjkr@d| d| |	 }i }|du rltj	
|}|jdu rUtdt j|jrd|j}|j|d< |jdurl|j}|tjksx|tjkrts|du rt|}|jdusJ ||j|I dH }tt| }|rt|t jjstd|du st|t jjsJ t| ||||||||||
|d	I dH S tst|rt|tjstd
|  }ddi}|tjtjfv }|tj tjfv }t j!" }|du rd}d}n|}|}|r	t#|}n|$ ||||||||d}tj||||d}|4 I dH I}|
rG|%dt&t'|d |(|j)||||d|I dH }nt*+|,d}|- } |(|j.||d| i|d|I dH }W d  I dH  n1 I dH svw   Y  |j/dk s|j/dkrt| d|j/ d|j0t j1j2|j0| j3| j4||d}!|j56 |!_7| 8|!st9|!S )a  Return the response obtained after sending a query via DNS-over-HTTPS.

    *client*, a ``httpx.AsyncClient``.  If provided, the client to use for
    the query.

    Unlike the other dnspython async functions, a backend cannot be provided
    in this function because httpx always auto-detects the async backend.

    See :py:func:`dns.query.https()` for the documentation of the other
    parameters, exceptions, and return type of this method.
    Nzhttps://:z	https://[z]:zno hostname in URLsni_hostnamez8client parameter must be a dns.quic.AsyncQuicConnection.)r{   r   
connectionz-client parameter must be an httpx.AsyncClientacceptzapplication/dns-messager   )local_addresshttp1http2r{   
local_portr   r   r;   )r   r   r{   	transport)zcontent-typezcontent-length)headerscontent
extensions   =r(   )r   paramsr      i+  z responded with status code z
Response body: rp   ):r(   rM   rN   
ValueError
is_addressr   r   r   urllibparseurlparsehostnamer   r	   H3DEFAULTr   r   resolve_namerandomchoicelist	addressesr'   quicAsyncQuicConnection_http3r
   httpxAsyncClientr+   H1H2rP   rQ   r   get_transport_classupdatestrre   wait_forr   base64urlsafe_b64encoderstripdecodegetstatus_coder   r)   r<   r3   r4   elapsedtotal_secondsr   r>   r   )"rG   rH   rI   r   rJ   rK   r2   r5   r   r   r   r{   r   r   r;   r   r   urlr   parsedanswersr@   r   h1h2rL   r   r   rW   r   
the_clientr`   twirerC   r   r   r   https  s   










*"r   r   r   c                    s  t jjs	tdtj|}|j}|d usJ |jd ur |j}d| _	| 
 }|r2t jj}t jj}nt j|
\}}| 4 I d H }|||	|dd4 I d H _}|rT|}n|||||}t|\}}||I d H }|4 I d H $ |||| |t|I d H }t| || W d   I d H  n1 I d H sw   Y  t }W d   I d H  n1 I d H sw   Y  t jj|| j| j||d}W d   I d H  n1 I d H sw   Y  t|| d|_| |st|S )Nz DNS-over-HTTP3 is not available.r   T)verify_modeserver_nameh3rp           )r(   r   	have_quicr
   r   r   r   r   r   idr+   null_factoryfactories_for_backendconnectr   make_streamsend_h3receiver   r   r   r   r)   r<   r3   r4   r   r>   r   )rG   rH   r   rI   r   rJ   rK   r2   r5   r{   rL   r   r   	url_partsr   r@   cfactorymfactorycontextthe_managerthe_connectionstartr    streamfinishrC   r   r   r   r     sZ   

(
((
r   r   c                    s  t jjs	td|dur|du r|}d| _|  }|r't jj}t jj}|}nt j|
\}}| 4 I dH }|||	|d4 I dH V}|sM|||||}t	|\}}|
|I dH }|4 I dH  ||dI dH  |t|I dH }W d  I dH  n1 I dH sw   Y  t }W d  I dH  n1 I dH sw   Y  t jj|| j| j||d}W d  I dH  n1 I dH sw   Y  t|| d|_| |st|S )ai  Return the response obtained after sending an asynchronous query via
    DNS-over-QUIC.

    *backend*, a ``dns.asyncbackend.Backend``, or ``None``.  If ``None``,
    the default, then dnspython will use the default backend.

    See :py:func:`dns.query.quic()` for the documentation of the other
    parameters, exceptions, and return type of this method.
    zDNS-over-QUIC is not available.Nr   )r   r   Trp   r   )r(   r   r   r   r   r+   r   r   r   r   r   sendr   r   r   r)   r<   r3   r4   r   r>   r   )rG   rH   rI   r   rJ   rK   r2   r5   r   r{   rL   r   rz   r@   r   r   r   r   r   r   r    r   r   rC   r   r   r   r     sV   (
((
r   txn_managerrZ   serialc                 C  s  |j d j}|tjjk}|  }| }	|jtj	k}
|
r1t
tjj|}||	dt|I dH  nt
tjj|}tdt|	|	 }|||I dH  tj| |||
}d}d}d}|st|\}}|du so|durq||krq|}|
rt|}|d|I dH \}}nt|d|I dH }td|\}t|||I dH }tjj||j|jd|||
 |d}||}|V  |j}|r]|jr|dur|j stj!"d	W d   dS W d   dS W d   dS 1 sw   Y  dS )
z'Given a socket, does the zone transfer.r   Nro   Fr9   rc   T)r3   r4   xfrorigintsig_ctxmultir2   zmissing TSIG)#questionrdtyper(   	rdatatypeIXFRfrom_wire_originr+   typer   rT   r   rP   DatagramSocketr,   r"   StreamSocketrq   packre   rg   r   Inboundr   r:   rn   rr   r)   r<   r3   rU   process_messager   had_tsig	exception	FormError)r   rZ   r8   r   rI   r    r   is_ixfrr   r@   is_udpr]   r^   rh   inbounddoner   rC   r[   mexpirationrwirers   rt   r   r   r   _inbound_xfrH  sb   	

"r   lifetimeudp_modec
              	      s  |du rt j|\}}
nt j|}
t j| }t|||}| |f}|	s+t j }	t	|\}}|j
d jt jjkr|tjkr|	|tjd||t|I dH }|4 I dH : zt||||
||2 z3 dH W }qa6 W W d  I dH  dS  t jjy   |tjkr Y nw W d  I dH  n1 I dH sw   Y  |	|tjd||t|I dH }|4 I dH  t||||
||2 z3 dH W }q6 W d  I dH  dS 1 I dH sw   Y  dS )am  Conduct an inbound transfer and apply it via a transaction from the
    txn_manager.

    *backend*, a ``dns.asyncbackend.Backend``, or ``None``.  If ``None``,
    the default, then dnspython will use the default backend.

    See :py:func:`dns.query.inbound_xfr()` for the documentation of
    the other parameters, exceptions, and return type of this method.
    Nr   )r(   r   
make_queryextract_serial_from_queryrM   rN   r   rP   rQ   r   r   r   r   r   r   NEVERrS   r   rT   r"   r   UseTCPONLYrw   )rH   r   r8   r   rI   r   rJ   rK   r   rL   r   r   rX   rY   r[   r    rZ   r   r   r   inbound_xfr  sZ   

	
(
.r   )N)
NNFFNr0   FFFN)NrF   Nr   FFFFNNF)NrF   Nr   FFFNNNF)NFNr0   F)NrF   Nr   FFNN)Nrx   Nr   FFNNNNT)
Nr   Nr   FFTNTN)Nrx   Nr   FFNTNNN)X__doc__r   
contextlibr   r   rq   r   urllib.parser   typingr   r   r   r   r   dns.asyncbackendr(   dns.exceptiondns.inetdns.messagedns.namedns.quicdns.rdatatypedns.transactiondns.tsigdns.xfrdns._asyncbackendr   	dns.queryr   r	   r
   r   r   r   r   r   r   r   r   sslImportErrordns._no_ssl_no_sslr   rM   low_level_address_tuplerO   r   r"   rP   r   r)   r*   bytesfloatintr/   boolnameNametsigKeyrE   r   Backendr\   r   ra   ri   rn   ru   r_   
SSLContextr~   r   	AF_UNSPECr   r   r   r   r   transactionTransactionManagerSocketr   r   r   r   r   r   r   <module>   sp  4



 	


@	



E	




G



!
	


@
	


F
	

 5	



C
	


F
:
	

