%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /lib/python2.7/site-packages/fail2ban/server/
Upload File :
Create Path :
Current File : //lib/python2.7/site-packages/fail2ban/server/ipdns.pyc

�
��&dc@s�dZdZdZddlZddlZddlZddlmZddlm	Z	e	e
�Zd	�Zd
d�Z
dfd
��YZdefd��YZedd�e_dS(sJFail2Ban Developers, Alexander Koeppe, Serg G. Brester, Yaroslav Halchenkos+Copyright (c) 2004-2016 Fail2ban DeveloperstGPLi����Ni(tUtilsi(t	getLoggercCst|t�r|St|�S(s8A little helper to guarantee ip being an IPAddr instance(t
isinstancetIPAddr(tip((s9/usr/lib/python2.7/site-packages/fail2ban/server/ipdns.pytasip'stc	Cs�y�|ptj�}d�tj|ddtjdtj�D�}|r�|d}d}x0|D](}|j|�ry|S|s`|}q`q`W|SWntjk
r�nXtj|�S(s�Get 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
	css#|]}|dr|dVqdS(iN((t.0tai((s9/usr/lib/python2.7/site-packages/fail2ban/server/ipdns.pys	<genexpr>4sit.N(	tsockettgethostnametgetaddrinfotNonet
SOCK_DGRAMtAI_CANONNAMEt
startswithterrortgetfqdn(tnametnamestpreftfirstR	((s9/usr/lib/python2.7/site-packages/fail2ban/server/ipdns.pyR-s "


tDNSUtilscBs�eZejdddd�Zejdddd
�Zed��Zed��Zed��Z	ee
d��Zed	��Zed
��Z
ed��ZRS(tmaxCounti�tmaxTimeii<cCsHtjj|�}|dk	r"|St�}d}x�tjtjftj	tj
ffD]�\}}y�x�tj|d|dtj�D]e}t
|�dks�t
|d�r�q�ntt|dd�|�}|jr�|j|�q�q�WWqVtk
r	}|}qVXqVW|r1|r1tjd||�ntjj||�|S(s_ Convert a DNS into an IP address using the Python socket module.
			Thanks to Kevin Drapel.
		iis4Unable to find a corresponding IP address for %s: %sN(RtCACHE_nameToIptgetRtsetRtAF_INETRtFAM_IPv4tAF_INET6tFAM_IPv6R
tIPPROTO_TCPtlentstrtisValidtaddt	ExceptiontlogSystwarning(tdnstipstsaveerrtfamtipfamtresultRte((s9/usr/lib/python2.7/site-packages/fail2ban/server/ipdns.pytdnsToIpSs&	1%#	
cCs�tjj|d�}|dkr%|Sytj|�d}Wn/tjk
rm}tjd||�d}nXtjj	||�|S(Nis'Unable to find a name for the IP %s: %s(((
RtCACHE_ipToNameRRt
gethostbyaddrRR(tdebugRR(RtvR0((s9/usr/lib/python2.7/site-packages/fail2ban/server/ipdns.pytipToNameqs
cCs�t�}tj|�}|dk	rLt|�}|jrL|j|�qLn|dkr�|r�tj|�}|j|�|r�|dkr�t	j
d||�q�n|S(s/ Return the IP of DNS found in a given text.
		tyestwarns'Determined IP using DNS Lookup: %s = %sN(syesswarn(RRtsearchIPRR%R&RR1tupdateR(R)(ttexttuseDnstipListtplainIPR((s9/usr/lib/python2.7/site-packages/fail2ban/server/ipdns.pyttextToIp�s		
	cCs�dd|f}tjj|�}|dkr�d}xc|rKttjfntjtfD]:}y|�}PWqXtk
r�}tj	d|�qXXqXWntjj
||�|S(s;Get short hostname or fully-qualified hostname of host selftselfthostnameRs#Retrieving own hostnames failed: %sN(RR2RRRRRR'R(R)R(tfqdntkeyRRAR0((s9/usr/lib/python2.7/site-packages/fail2ban/server/ipdns.pytgetHostname�s(	cCsrd}tjj|�}|dkr[tdtjt�tjt�g�tdg�}ntjj||�|S(sGet own host names of selfR@R*t	localhostR(sselfsdnsN(RR2RRRRDtFalsetTrue(RCR((s9/usr/lib/python2.7/site-packages/fail2ban/server/ipdns.pytgetSelfNames�s!cCs�d}tjj|�}|dkr�t�}x`tj�D]O}y |ttj|d��O}Wq:tk
r�}tj	d||�q:Xq:Wntjj||�|S(sGet own IP addresses of selfR@R+R7s#Retrieving own IPs of %s failed: %s(sselfsipsN(
RRRRRRHR?R'R(R)(RCR+RAR0((s9/usr/lib/python2.7/site-packages/fail2ban/server/ipdns.pyt
getSelfIPs�s	 cCstd�tj�D��S(Ncss|]}d|jkVqdS(t:N(tntoa(RR((s9/usr/lib/python2.7/site-packages/fail2ban/server/ipdns.pys	<genexpr>�s(tanyRRI(((s9/usr/lib/python2.7/site-packages/fail2ban/server/ipdns.pyt
IPv6IsAllowed�si,i,(t__name__t
__module__RtCacheRR2tstaticmethodR1R6R?RGRDRHRIRM(((s9/usr/lib/python2.7/site-packages/fail2ban/server/ipdns.pyRMsRcBseZdZdZdZejdeef�Zd1Z	d2Z
ejd	d
dd3�Z
dZdZeejZeejZed�Zed��Zed�Zd�Zd�Zd�Zed��Zed��Zidej6dej6Zed��Z ed��Z!ed��Z"ed��Z#ed��Z$d�Z%d �Z&d!�Z'd"�Z(d#�Z)d$�Z*ed%��Z+ed&��Z,d1d'�Z-d(�Z.ed)��Z/ed*��Z0d+�Z1d,�Z2d-�Z3e3�Z4ed.��Z5ed/��Z6ed0��Z7RS(4s7Encapsulate functionality for IPv4 and IPv6 addresses
	s(?:\d{1,3}\.){3}\d{1,3}s;(?:[0-9a-fA-F]{1,4}::?|::){1,7}(?:[0-9a-fA-F]{1,4}|(?<=:):)s%^(?:(?P<IPv4>%s)|\[?(?P<IPv6>%s)\]?)$t_familyt_addrt_plent	_maskplent_rawRi'Rii<i����i����cCs$|tjkr;tt|�j|�}|j||�|S||f}tjj|�}|dk	ri|S|tjkr�tj	|�\}}||f}|tjkr�tjj|�}|dk	r�|Sq�ntt|�j|�}|j||�|j
tjkr tjj||�n|S(N(RtCIDR_RAWtsupert__new__t
_IPAddr__initt	CACHE_OBJRRtCIDR_UNSPECt_IPAddr__wrap_ipstrRRR(tclstipstrtcidrRtargs((s9/usr/lib/python2.7/site-packages/fail2ban/server/ipdns.pyRY�s(
cCs�t|�dkrB|ddkrB|ddkrB|dd!}nd|kr[|tjfS|jdd�}t|�dkr�td|f��nd	|dks�d
|dkr�tj|d�|d<nt|d�|d<|S(Niit[i����t]it/s.invalid ipstr %r, too many plen representationR
RJ(R#RR\tsplitt
ValueErrort
masktoplentlong(R_ts((s9/usr/lib/python2.7/site-packages/fail2ban/server/ipdns.pyt__wrap_ipstrs2
 cCs
tj|_d|_d|_d	|_||_|tj	kr�|d	k	rm|tj	krmtj	|g}ntj
tjg}xH|D]@}y tj||�}||_PWq�tj
k
r�q�q�Xq�W|jtj
kr>tjd|�\|_d|_|d	k	r�|dkr�d|?}|j|M_||_q�q	|jtjkr	tjd|�\}}|d>|B|_d|_|d	k	r�|dkr�d|?}|j|M_||_q�|jtj�r�|d@|_tj
|_d|_q�q	ntj	|_d	S(
sP initialize IP object by converting IP address string
			to binary to integer
		is!Li l��s!QQi@i�l	���������N(Rt	AF_UNSPECRRRSRTRRURVRRWRR t	inet_ptonRtstructtunpacktisInNettIP6_4COMPAT(R@R_R`tfamilytbinarytmaskthitlo((s9/usr/lib/python2.7/site-packages/fail2ban/server/ipdns.pyt__initsH				
			
cCs
t|j�S(N(treprRK(R@((s9/usr/lib/python2.7/site-packages/fail2ban/server/ipdns.pyt__repr__PscCs&t|jt�r|jSt|j�S(N(RRKt
basestringR$(R@((s9/usr/lib/python2.7/site-packages/fail2ban/server/ipdns.pyt__str__SscCst|jffS(s�IPAddr pickle-handler, that simply wraps IPAddr to the str

		Returns a string as instance to be pickled, because fail2ban-client can't
		unserialize IPAddr objects
		(R$RK(R@((s9/usr/lib/python2.7/site-packages/fail2ban/server/ipdns.pyt
__reduce__VscCs|jS(N(RS(R@((s9/usr/lib/python2.7/site-packages/fail2ban/server/ipdns.pytaddr^scCs|jS(N(RR(R@((s9/usr/lib/python2.7/site-packages/fail2ban/server/ipdns.pyRqbstinet4tinet6cCstjj|j�S(N(RtFAM2STRRRR(R@((s9/usr/lib/python2.7/site-packages/fail2ban/server/ipdns.pyt	familyStrgscCs|jS(N(RT(R@((s9/usr/lib/python2.7/site-packages/fail2ban/server/ipdns.pytplenkscCs|jS(slThe raw address

		Should only be set to a non-empty string if prior address
		conversion wasn't possible
		(RV(R@((s9/usr/lib/python2.7/site-packages/fail2ban/server/ipdns.pytrawoscCs|jtjkS(s6Either the object corresponds to a valid IP address
		(RRRRk(R@((s9/usr/lib/python2.7/site-packages/fail2ban/server/ipdns.pyR%xscCs0|jidtj6dtj6j|jd�kS(sIReturns whether the object is a single IP address (not DNS and subnet)
		i i�i���(RTRRR RRR(R@((s9/usr/lib/python2.7/site-packages/fail2ban/server/ipdns.pytisSingle~scCs�|jtjkr/t|t�r/|j|kSt|t�s]|dkrNtSt|�}n|j|jkrstS|jtjkr�|j|jkS|j	|j	ko�|j
|j
kS(N(RRRRWRRVRRFRRkRSRT(R@tother((s9/usr/lib/python2.7/site-packages/fail2ban/server/ipdns.pyt__eq__�s"
cCs||kS(N((R@R�((s9/usr/lib/python2.7/site-packages/fail2ban/server/ipdns.pyt__ne__�scCs|jtjkr/t|t�r/|j|kSt|t�s]|dkrNtSt|�}n|j|jkp~|j|jkS(N(RRRRWRRVRRFRS(R@R�((s9/usr/lib/python2.7/site-packages/fail2ban/server/ipdns.pyt__lt__�s"
cCs,t|t�st|�}nd||fS(Ns%s%s(RR(R@R�((s9/usr/lib/python2.7/site-packages/fail2ban/server/ipdns.pyt__add__�scCs,t|t�st|�}nd||fS(Ns%s%s(RR(R@R�((s9/usr/lib/python2.7/site-packages/fail2ban/server/ipdns.pyt__radd__�scCs
t|j�S(N(thashRK(R@((s9/usr/lib/python2.7/site-packages/fail2ban/server/ipdns.pyt__hash__�scCsB|jtjkrd|jS|jtjkr:d|jSdSdS(s<Hex representation of the IP address (for debug purposes)
		s%08xs%032xRN(RRRRRSR (R@((s9/usr/lib/python2.7/site-packages/fail2ban/server/ipdns.pythexdump�s
cCs�d}|jrOtjd|j�}|jr�|jdkr�d|j}q�nj|jr�|jd?}|jd@}tjd||�}|jr�|jdkr�d|j}q�n|jStj|j	|�|S(	si represent IP object as text like the deprecated
			C pendant inet.ntoa but address family independent
		Rs!Li s/%di@l����s!QQi�(
tisIPv4RmtpackRSRTtisIPv6RVRt	inet_ntopRR(R@R&RrRtRu((s9/usr/lib/python2.7/site-packages/fail2ban/server/ipdns.pyRK�s		

cCs~|jr3|jjd�}|dkrad}qan.|jr]|j}|dkrad}qandSddjt|��|fS(s return the DNS PTR string of the provided IP address object

			If "suffix" is provided it will be appended as the second and top
			level reverse domain.
			If omitted it is implicitly set to the second and top level reverse
			domain of the according IP address family
		R
s
in-addr.arpa.s	ip6.arpa.Rs%s.%sN(R�RKReRR�R�tjointreversed(R@tsuffixtexploded_ip((s9/usr/lib/python2.7/site-packages/fail2ban/server/ipdns.pytgetPTR�s			cCstj|j�S(s?Return the host name (DNS) of the provided IP address object
		(RR6RK(R@((s9/usr/lib/python2.7/site-packages/fail2ban/server/ipdns.pytgetHost�scCs|jtjkS(s4Either the IP object is of address family AF_INET
		(RqRR(R@((s9/usr/lib/python2.7/site-packages/fail2ban/server/ipdns.pyR��scCs|jtjkS(s5Either the IP object is of address family AF_INET6
		(RqRR (R@((s9/usr/lib/python2.7/site-packages/fail2ban/server/ipdns.pyR��scCs�|jr/|jdkr/|tj|j�kS|j|jkrEtS|jr_d|j?}n|jryd|j?}ntS|j	|@|j	kS(s9Return either the IP object is in the provided network
		Rl��l	���������(
R%R�RR1RqRFR�R�R�R|(R@tnetRs((s9/usr/lib/python2.7/site-packages/fail2ban/server/ipdns.pyRo�s		cCs(t|t�o'||kp'|j|�S(s;Return whether the object (as network) contains given IP
		(RRRo(R@R((s9/usr/lib/python2.7/site-packages/fail2ban/server/ipdns.pytcontainsscCs�d}d}id|6d|6dd6}d}xXtdd�D]G}|d|>O}|dkrrd	||||A<nd
||||A<q=W|S(Nii�i il	l	���������II����ii(txrange(tm6tm4tmmaptmti((s9/usr/lib/python2.7/site-packages/fail2ban/server/ipdns.pyt__getMaskMapscCsfd}|jdk	r|jStjj|j�}|dkrYtdt|�f��n||_|S(Nis'invalid mask %r, no plen representation(RURRtMAP_ADDR2MASKPLENRRSRfR$(R@tmplen((s9/usr/lib/python2.7/site-packages/fail2ban/server/ipdns.pytmaskplens	cCs
t|�jS(sIConvert mask string to prefix length

		To be used only for IPv4 masks
		(RR�(Rs((s9/usr/lib/python2.7/site-packages/fail2ban/server/ipdns.pyRg'scCsHtjj|�}|sdS|jd�}|dkr;|S|jd�S(sBSearch if text is an IP address, and return it if so, else None
		tIPv4RtIPv6N(Rt
IP_4_6_CREtmatchRtgroup(R;R�R_((s9/usr/lib/python2.7/site-packages/fail2ban/server/ipdns.pyR9/sN(s_familys_addrs_plens	_maskplens_rawi,(8RNROt__doc__tIP_4_REtIP_6_REtretcompileR�RRpt	__slots__RRPR[RWR\RRRR R!RYRQR]RZRxRzR{tpropertyR|RqRR�R�R�R%R�R�R�R�R�R�R�R�RKR�R�R�R�RoR�t_IPAddr__getMaskMapR�R�RgR9(((s9/usr/lib/python2.7/site-packages/fail2ban/server/ipdns.pyR�sZ

7															s
::ffff:0:0i`(t
__author__t
__copyright__t__license__RRmR�tutilsRthelpersRRNR(RRRtobjectRRp(((s9/usr/lib/python2.7/site-packages/fail2ban/server/ipdns.pyt<module>s	 ��f

Zerion Mini Shell 1.0