
    Q:h                     l   d dl Z d dlZd dlZd dlZd dlmZ e j                            e          Ze j        	                    e          Z
 e j        e
           dZdZdZdZdZddd	Zd
edefdZded
ededz  fdZdedededededej        j        fdZdededededej        j        f
dZd ZdS )    N)
log_outputz./IPz https://www.hover.com/api/dns/{}z!https://www.hover.com/api/domainszhttps://www.hover.com/api/dnsz,https://www.hover.com/api/control_panel/dns/zhttp://127.0.0.1:8080)httphttpsuse_ipv6returnc                 J    |rdnd}t          j        || d          }|j        S )z@
    Retrieves the external IP address using the ipify API.
    zhttps://api6.ipify.orgzhttps://api.ipify.orgT)proxiesverify)requestsgettext)r	   r   apiresponses       1/home/seanl/mnt/public/Repos/hover-dyn-dns/dns.pyget_external_ipr      s3     '/
K
"
"4KC|C>>>H=    domainc                     t          j        | d|rt           j        j        nt           j        j                  D ]3}t          |d         d         t                    r|d         d         c S 4dS )z,Retrieves the IP address for a given domain.P      r   N)socketgetaddrinfoAddressFamilyAF_INET6AF_INET
isinstancestr)r   r   addrinfos      r   
get_dns_ipr   !   su    &vrT\3~63G3P3Pbhbvb~ " "hqk!nc** 	"A;q>!!!	"" "r   dns_entry_id	subdomainnew_ip_addressrecord_typecookiesc           	         d| | |||ddddgd|ddd}t          j        t          |||d	          }t          t                              |                      t          d
|j                    t          d|j                    |S )z9
    Updates an existing DNS record with a known ID.
    domain-900FT)idnametypecontentttl
is_default
can_revert)r(   dns_records)r+   r,   )r   fieldsurljsonr$   r	   r
   !DNS update response status code: DNS update response content: )r   putDNS_SUBENTRIES_URLr   DNS_UPDATE_URLformatstatus_coder+   )	r    r   r!   r"   r#   r$   r	   put_datar   s	            r    submit_put_on_existing_dns_entryr<   '   s     %F$$ '%'- "'"& 

 
 &
 
 H* | 27\clpqqqH~$$\22333I83GIIJJJAx/?AABBBOr   c                     |||ddd|  d}t          t          |                     t          j        t          |||d          }t          d|j                    t          d|j                    |S )	z 
    Adds a new DNS record.
    r'   )r)   r+   r*   r,   r&   )
dns_recordr(   Tr1   r4   r5   )r   r   r   postr7   r:   r+   )r   r!   r"   r#   r$   r	   	post_datar   s           r   submit_post_for_new_dns_entryrA   G   s     %	
 
 !   I s9~~}!3)W^enrsssHI83GIIJJJAx/?AABBBOr   c                     t          j        t          | |d          }|j        dk    r|                                S  |d|j         d|j         |           t          d           dS )z4
    Retrieves the DNS entries for the account.
    T)r$   r	   r
      z-Failed to retrieve DNS entries. Status code: z, Response text: r   N)r   r   DNS_ENTRIES_URLr:   r3   r   exit)r$   r	   loggingr   s       r   get_dns_entriesrG   [   s|     |OWgVZ[[[Hs""}}v@Tvvgogtvvx  	A  	A  	AQr   )osr   r   requests.cookieslogging_outr   pathabspath__file__dirnamednamechdirIP_FILEr8   DOMAIN_CHECK_URLrD   r7   DEFAULT_PROXIESboolr   r   r   r$   RequestsCookieJarr<   rA   rG    r   r   <module>rW      s   				       " " " " " "
'//(
#
#
   
36 1C  $$ 
t     "s "d "sTz " " " "3  PS eh wz   FN  FV  Fh    @# # s ad owo  pR    (	 	 	 	 	r   