3 ‡Of½Lã@sŠdZddlmZddlZddlZddlZddlZddlZddlZddl Z ddl Z ddl Z ddl Z ddlZ ddlZ ddlmZmZejd/kr�eZnejZejZGdd„de jjƒZGd d „d e jjƒZd d „Zd d„Zdd„Zdd„Z dd„Z!e"edƒrüea#nea#dd„Z$dd„Z%dd„Z&dd„Z'dd„Z(d0d"d#„Z)d$d%„Z*d&d'„Z+d(d)„Z,d1d*d+„Z-e j.j/e j0j1dd ddd,dddddd!e j2j3fd-d.„Z4dS)2zTalk to a DNS server.é)Ú generatorsNé)ÚlongÚ string_typeséc@seZdZdZdS)ÚUnexpectedSourcez=A DNS query response came from an unexpected address or port.N)Ú__name__Ú __module__Ú __qualname__Ú__doc__©r r ú/usr/lib/python3.6/query.pyr,src@seZdZdZdS)Ú BadResponsezd}t|ƒ}x,||kr8t||ƒ||j||d…ƒ7}qWdS)z‘Write the specified data to the socket. A Timeout exception will be raised if the operation is not completed by the expiration time. rN)rQr*Úsend)rRÚdatar"ZcurrentÚlr r r Ú _net_write/s   rYc Cspy|j|ƒWn\tjk rjtjƒdd…\}}t|dƒrF|j}n|d}|tjtjtj gkrf|‚YnXdS)Nér!r) Zconnectr>rÚsysÚexc_infoÚhasattrr!Z EINPROGRESSZ EWOULDBLOCKZEALREADY)r(ZaddressZtyÚvZv_errr r r Ú_connect;s r_cCs |jƒ}t|||||ƒ\}} }t|tjdƒ} d} z„t|ƒ} | jdƒtjƒ} |dk r^| j|ƒt | | ƒt |ƒ} t j d| ƒ|}t | || ƒt| d| ƒ}t jd|ƒ\} t| | | ƒ}Wd| dkrÄd}n tjƒ| }| jƒXtjj||j|j|d�}||_|j|ƒ�st‚|S)aReturn the response obtained after sending a query via TCP. @param q: the query @type q: dns.message.Message object @param where: where to send the message @type where: string containing an IPv4 or IPv6 address @param timeout: The number of seconds to wait before the query times out. If None, the default, wait forever. @type timeout: float @param port: The port to which to send the message. The default is 53. @type port: int @param af: the address family to use. The default is None, which causes the address family to use to be inferred from the form of where. If the inference attempt fails, AF_INET is used. @type af: int @rtype: dns.message.Message object @param source: source address. The default is the wildcard address. @type source: string @param source_port: The port from which to send the message. The default is 0. @type source_port: int @param one_rr_per_rrset: Put each RR into its own RRset @type one_rr_per_rrset: bool rNz!HrZ)r9r:r;)r<r7r=r>Ú SOCK_STREAMrr@rrAr_rQÚstructÚpackrYrUÚunpackrGrrCrDr9rErFr)rHr3rr4r,r5r6r;rJr/r(rKr"rXÚtcpmsgÚldatarLrMr r r ÚtcpIs8        rfTc& csÀt|tƒrtjj|ƒ}t|tƒr,tjj|ƒ}tjj|||ƒ}|tjjkrltj j|dddd| ƒ}|j j |ƒ|dk r„|j |||d�|j ƒ}t| ||| | ƒ\} }} |rÊ|tjjkrºtdƒ‚t| tjdƒ}nt| tjdƒ}|jdƒ| dk rô|j| ƒt| ƒ}t||ƒt|ƒ}|�r*t||ƒ|j|ƒntjd|ƒ|}t|||ƒd }d }d }d}|�rj|}tjj}nd}|}d}d }�x6|�s²t|ƒ} | dk�sª|dk �r®| |k�r®|} |�rÎt||ƒ|j d ƒ\}}!n&t!|d | ƒ}"tj"d|"ƒ\}t!||| ƒ}|tjjk}#tjj#||j$|j%d ||d ||#d � }$|$j&}d }d}%|dk�r¼|$j' �sV|$j'dj|k�rbtj(j)dƒ‚|$j'd}|j*tjj+k�rˆtj(j)dƒ‚d}%|j,ƒ}|tjjk�r¼|dj-| k�r¸d }nd }xÆ|$j'|%d…D]´}|�râtj(j)dƒ‚|j*tjj+k�rl|j|k�rl|�r&|dj-| k�r tj(j)dƒ‚d }n|tjjk�r:| }||k�r~|tjj.k�sf|tjjk�r~|�r~d }n|�rÌtjj.}d }�qÌW|�r¨|j$�r¨|$j/ �r¨tj(j)dƒ‚|$V�q~W|j0ƒdS)aƒReturn a generator for the responses to a zone transfer. @param where: where to send the message @type where: string containing an IPv4 or IPv6 address @param zone: The name of the zone to transfer @type zone: dns.name.Name object or string @param rdtype: The type of zone transfer. The default is dns.rdatatype.AXFR. @type rdtype: int or string @param rdclass: The class of the zone transfer. The default is dns.rdataclass.IN. @type rdclass: int or string @param timeout: The number of seconds to wait for each response message. If None, the default, wait forever. @type timeout: float @param port: The port to which to send the message. The default is 53. @type port: int @param keyring: The TSIG keyring to use @type keyring: dict @param keyname: The name of the TSIG key to use @type keyname: dns.name.Name object or string @param relativize: If True, all names in the zone will be relativized to the zone origin. It is essential that the relativize setting matches the one specified to dns.zone.from_xfr(). @type relativize: bool @param af: the address family to use. The default is None, which causes the address family to use to be inferred from the form of where. If the inference attempt fails, AF_INET is used. @type af: int @param lifetime: The total number of seconds to spend doing the transfer. If None, the default, then there is no limit on the time the transfer may take. @type lifetime: float @rtype: generator of dns.message.Message objects. @param source: source address. The default is the wildcard address. @type source: string @param source_port: The port from which to send the message. The default is 0. @type source_port: int @param serial: The SOA serial number to use as the base for an IXFR diff sequence (only meaningful if rdtype == dns.rdatatype.IXFR). @type serial: int @param use_udp: Use UDP (only meaningful for IXFR) @type use_udp: bool @param keyalgorithm: The TSIG algorithm to use; defaults to dns.tsig.default_algorithm @type keyalgorithm: string rÚINÚSOAz. . %u 0 0 0 0N)Ú algorithmzcannot do a UDP AXFRz!HFTiÿÿrZ)r9r:ÚxfrÚoriginÚtsig_ctxZmultiÚfirstr;z No answer or RRset not for qnamezfirst RRset is not an SOArzanswers after final SOAzIXFR base serial mismatchz missing TSIG)1Ú isinstancerrÚnameZ from_textÚ rdatatyperCZ make_queryZIXFRÚrrsetZ authorityÚappendZuse_tsigr<r7Ú ValueErrorr=r>r?r`r@rArr_rQr*rVrarbrYÚemptyr)rBrUrcrDr9rErlZanswerrÚ FormErrorÚrdtyperhÚcopyÚserialÚAXFRZhad_tsigrG)&r3ZzonervZrdclassrr4r9ZkeynameZ relativizer,Zlifetimer5r6rxZuse_udpZ keyalgorithmrHrqrJr/r(r"rXrdr#Z delete_modeZ expecting_SOAZ soa_rrsetrkZonamerlrmZ mexpirationr.reZis_ixfrrMZ answer_indexr r r rj‰s¾5                             rj)r)Nr8NNrFFF)Nr8NNrF)5r Z __future__rr!rr>rar[rZ dns.exceptionrZdns.inetZdns.nameZ dns.messageZdns.rdataclassZ dns.rdatatypeZ_compatrrÚ version_infoÚOSErrorrrr=rZ DNSExceptionrrurrrrr%r'r]rr)r*r-r1r7rNrUrYr_rfrpryZ rdataclassrgZtsigZdefault_algorithmrjr r r r ÚsX     I  ?