/usr/lib/python3/dist-packages/fail2ban/server/__pycache__
Edit: /usr/lib/python3/dist-packages/fail2ban/server/__pycache__/ipdns.cpython-310.pyc (13825B)
o
;s*b@ @ s d Z dZdZddlZddlZddlZddlmZ ddlm Z e e
Zd d
Zddd
Z
G dd dZG dd deZedde_dS )zJFail2Ban Developers, Alexander Koeppe, Serg G. Brester, Yaroslav Halchenkoz+Copyright (c) 2004-2016 Fail2ban DevelopersGPL N )Utils ) getLoggerc C s t | tr| S t| S )z8A little helper to guarantee ip being an IPAddr instance
isinstanceIPAddr)ip r 7/usr/lib/python3/dist-packages/fail2ban/server/ipdns.pyasip' s
r
c C s z7| pt } dd t | ddt jdt jD }|r6| d }d}|D ]}||r.| W S |s2|}q"|W S W n
t jyA Y nw t | S )zGet fully-qualified hostname of given host, thereby resolve of an external
IPs and name will be preferred before the local domain (or a loopback), see gh-2438
c s s | ]}|d r|d V qdS ) Nr ).0air r r
3 s
zgetfqdn..Nr .)socketgethostnamegetaddrinfo
SOCK_DGRAMAI_CANONNAME
startswitherrorgetfqdn)namenamespreffirstr r r r r - s*
r c @ s~ e Zd ZejdddZejdddZedd Zedd Z edd Z
edddZed
d Zedd Z
edd ZdS )DNSUtilsi , maxCountmaxTimec C s t j| }|dur|S t }d}tjtjftjtj ffD ]G\}}z/t
| d|dtjD ]"}t|dk s:t|d s;q,tt
|d d |}|jrN|| q,W q tyd } z|}W Y d}~qd}~ww |sp|rptd| | t j| | |S )z_ Convert a DNS into an IP address using the Python socket module.
Thanks to Kevin Drapel.
Nr z4Unable to find a corresponding IP address for %s: %s)r CACHE_nameToIpgetsetr AF_INETr FAM_IPv4AF_INET6FAM_IPv6r IPPROTO_TCPlenstrisValidadd ExceptionlogSyswarning)dnsipssaveerrfamipfamresultr
er r r dnsToIpS s,
zDNSUtils.dnsToIpc
C sx t j| d}|dkr
|S z t| d }W n tjy2 } ztd| | d }W Y d }~nd }~ww t j| | |S )Nr r z'Unable to find a name for the IP %s: %s) r CACHE_ipToNamer' r
gethostbyaddrr r3 debugr( )r
vr; r r r ipToNameq s zDNSUtils.ipToNamec C sn t }t| }|durt|}|jr|| |dv r5|s5t| }|| |r5|dkr5t d| | |S )z/ Return the IP of DNS found in a given text.
N)yeswarnrC z'Determined IP using DNS Lookup: %s = %s)
r( r searchIPr0 r1 r r<