3 OfL@sdZddlmZddlZddlZddlZddlZddlZddlZddl Z ddl Z ddl Z ddl Z ddlZ ddlZ ddlmZmZejd/kreZnejZejZGddde jjZGd d d e jjZd d Zd dZddZddZ ddZ!e"edrea#nea#ddZ$ddZ%ddZ&ddZ'ddZ(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_typesc@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||d7}qWdS)zWrite 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)rRdatar"Zcurrentlr r r _net_write/s   rYc Cspy|j|Wn\tjk rjtjdd\}}t|drF|j}n|d}|tjtjtj gkrf|YnXdS)Nr!r) Zconnectr>rsysexc_infohasattrr!Z EINPROGRESSZ EWOULDBLOCKZEALREADY)r(ZaddressZtyvZv_errr r r _connect;s r_cCs |j}t|||||\}} }t|tjd} d} zt|} | jdtj} |dk r^| j|t | | t |} t j d| |}t | || t| d| }t jd|\} t| | | }Wd| dkrd}n tj| }| jXtjj||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_rQstructpackrYrUunpackrGrrCrDr9rErFr)rHr3rr4r,r5r6r;rJr/r(rKr"rXtcpmsgldatarLrMr r r tcpIs8        rfTc& cst|trtjj|}t|tr,tjj|}tjj|||}|tjjkrltj j|dddd| }|j j ||dk r|j |||d|j }t| ||| | \} }} |r|tjjkrtdt| 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|st|} | dks|dk r| |kr|} |rt|||j d \}}!n&t!|d | }"tj"d|"\}t!||| }|tjjk}#tjj#||j$|j%d ||d ||#d }$|$j&}d }d}%|dkr|$j' sV|$j'dj|krbtj(j)d|$j'd}|j*tjj+krtj(j)dd}%|j,}|tjjkr|dj-| krd }nd }x|$j'|%dD]}|rtj(j)d|j*tjj+krl|j|krl|r&|dj-| kr tj(j)dd }n|tjjkr:| }||kr~|tjj.ksf|tjjkr~|r~d }n|rtjj.}d }qW|r|j$r|$j/ rtj(j)d|$Vq~W|j0dS)aReturn 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 rINSOAz. . %u 0 0 0 0N) algorithmzcannot do a UDP AXFRz!HFTirZ)r9r:xfrorigintsig_ctxZmultifirstr;z No answer or RRset not for qnamezfirst RRset is not an SOArzanswers after final SOAzIXFR base serial mismatchz missing TSIG)1 isinstancerrnameZ from_text rdatatyperCZ make_queryZIXFRrrsetZ authorityappendZuse_tsigr<r7 ValueErrorr=r>r?r`r@rArr_rQr*rVrarbrYemptyr)rBrUrcrDr9rErlZanswerr FormErrorrdtyperhcopyserialAXFRZhad_tsigrG)&r3ZzonervZrdclassrr4r9ZkeynameZ relativizer,Zlifetimer5r6rxZuse_udpZ keyalgorithmrHrqrJr/r(r"rXrdr#Z delete_modeZ expecting_SOAZ soa_rrsetrkZonamerlrmZ mexpirationr.reZis_ixfrrMZ answer_indexr r r rjs5                             rj)r)Nr8NNrFFF)Nr8NNrF)5r Z __future__rr!rr>rar[rZ dns.exceptionrZdns.inetZdns.nameZ dns.messageZdns.rdataclassZ dns.rdatatypeZ_compatrr version_infoOSErrorrrr=rZ DNSExceptionrrurrrrr%r'r]rr)r*r-r1r7rNrUrYr_rfrpryZ rdataclassrgZtsigZdefault_algorithmrjr r r r sX     I  ?