%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /lib/python2.7/site-packages/salt/utils/
Upload File :
Create Path :
Current File : //lib/python2.7/site-packages/salt/utils/network.pyc

�
���^c@@s=dZddlmZmZmZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZddlZddl
Z
ddlmZmZddlmZddlmZyddlZddlZWnek
r�nXddlZddlZddlZddlZddlZddlZddlm Z ddl!m"Z"m#Z#dd	l$m%Z%dd
l&m'Z'ej(jj)�r�ddlm*Z*ne
j+e,�Z-yCddl.Z.ddl/Z.e.j0j1e.j2j3d��Z4e4j5Z6Wnee7e8e9fk
rnXd
�Z:d�Z;d�Z<d�Z=d�Z>e	j?dd�Z@d�ZAd�ZBd�ZCd�ZDd�ZEd�ZFd�ZGd�ZHd�ZIe%d�dd��ZKd�ZLd�ZMd �ZNd!�ZOd"�ZPd#�ZQd$�ZRd%�ZSdd&�ZTdd'�ZUe%d(�dd)��ZVe%d*�dd+��ZWdd,�ZXe%d-�dd.��ZYe%d/�dd0��ZZe%d1�dd2��Z[dd3�Z\e%d4�ddd5��Z]d6�Z^e%d7�ddd8��Z_d9�Z`e%d:�ddd;��Zad<d=�Zbd>�Zcd?�Zdd@�ZedA�ZfdB�ZgdC�ZhdD�ZidE�ZjdF�ZkdG�ZldH�ZmdI�ZndJ�ZodK�ZpddL�ZqdM�ZrdN�ZsdO�ZtdP�ZudQ�ZvdR�ZwdSddT�ZxddU�ZydV�ZzddW�Z{de|ddSdX�Z}de|ddY�Z~de|ddZ�Ze|d[�Z�dd\�Z�d]�Z�d^�Z�d_�Z�d`�Z�da�Z�db�Z�dc�Z�dd�Z�de�Z�df�Z�dg�Z�dh�Z�di�Z�e%dj�dkdl��Z�e%dm�dn��Z�do�Z�e%dp�e|ddq��Z�dr�Z�ds�Z�dS(tu:
Define some generic socket functions for network modules
i(tabsolute_importtunicode_literalstprint_functionN(t
ascii_letterstdigits(tsix(trange(t	ipaddress(tSaltClientErrortSaltSystemExit(tjinja_filter(tLooseVersion(t
win_inet_ptonuccC@sAttd}djg|dd!D]}||kr"|^q"�S(uS
    Sanitize host string.
    https://tools.ietf.org/html/rfc1123#section-2.1
    u.-uii�(RRtjoin(thosttRFC952_characterstc((s6/usr/lib/python2.7/site-packages/salt/utils/network.pyt
sanitize_host:scC@scdt|�kodkns&tStjtjtj�}|jt|�t|�f�}|S(u!
    Return status of a port
    ii��(tinttFalsetsockettAF_INETtSOCK_STREAMt
connect_exR(Rtporttsocktout((s6/usr/lib/python2.7/site-packages/salt/utils/network.pyt
isportopenCs
"!cC@s�g}y�x�tj|dtjtj�D]d\}}}}}|tjkr[|\}}n$|tjkr|\}}}	}
n|j|�q(W|s�d}nWntk
r�d}nX|S(uR
    Returns a list of IP addresses of a given hostname or None if not found.
    iN(	Rtgetaddrinfot	AF_UNSPECRRtAF_INET6tappendtNonet	Exception(Rtipstfamilytsocktypetprotot	canonnametsockaddrtipRt	flow_infotscope_id((s6/usr/lib/python2.7/site-packages/salt/utils/network.pythost_to_ipsQs	+


c	
C@sSdtfd��Y}tj�}|�jtjjjtjtjjj	|����jt
j��j|�}|s,ykxdtj|j
�p�ddtjtjtjtj�D],}t|�dkr�|j|d�q�q�WWq,tjk
r(tjdjd|j
�pddtj��q,Xnx�d	d
ddjd
tjd��fD]�}y�tjjj|���}x�|D]}tjjj|�}|j�jd�dj�j�}|r||dd dks�t|�dkr�|j|�q�q|q|WWdQXWqTtk
rqTXqTW|jgt �D]}t!j"|�j#s.|^q.�S(uM
    Get list of possible host names and convention names.

    :return:
    tDistinctListc	B@sSeZdZddddddddd	g	Zd
�Zd�Zd�Zd
�ZRS(u�
        List, which allows one to append only distinct objects.
        Needs to work on Python 2.6, because of collections.OrderedDict only since 2.7 version.
        Override 'filter()' for custom filtering.
        ulocalhost.*uip6-.*u127[.]\du
0\.0\.0\.0u::1.*uipv6-.*ufe00::.*ufe02::.*u1.0.0.*.ip6.arpacS@sB|r>||kr>|j|�r>t|j|�j|�n|S(N(tfiltertsupert	__class__R(tselftp_object((s6/usr/lib/python2.7/site-packages/salt/utils/network.pyRys"cS@s"x|D]}|j|�qW|S(N(R(R0titerabletobj((s6/usr/lib/python2.7/site-packages/salt/utils/network.pytextend~s
cS@s.x'|jD]}tj||�r
tSq
WdS(u,Returns True if element needs to be filteredN(tlocalhost_matcherstretmatchtTrue(R0telementtrgx((s6/usr/lib/python2.7/site-packages/salt/utils/network.pyR-�scS@s|r|dpdS(Ni(R (R0((s6/usr/lib/python2.7/site-packages/salt/utils/network.pytfirst�s(t__name__t
__module__t__doc__R5RR4R-R;(((s6/usr/lib/python2.7/site-packages/salt/utils/network.pyR,ps			u	localhostiu8Cannot resolve address {addr} info via socket: {message}taddrulocalhost (N/A)tmessageu
/etc/hostnameu
/etc/nodenameu
/etc/hostsu {win}\system32\drivers\etc\hoststwinuWINDIRu#iiu127.u::1iN(u127.u::1($tlistRtgethostnameRtsalttutilststringutilst
to_unicodetgetfqdntto_bytestplatformtnodeRR;R RtSOCK_RAWt
IPPROTO_IPtAI_CANONNAMEtlentgaierrortlogtwarningtformattostgetenvtfilestfopentstriptsplitR4tIOErrortip_addrsRt
ip_addresstis_loopback(	R,thostnamethoststa_nfotf_nametf_hdltlinethstR?((s6/usr/lib/python2.7/site-packages/salt/utils/network.pyt_generate_minion_ides8	0!&"
%&!
cC@sFy"tjjjt�j��}Wntk
r;d}nX|pEdS(uY
    Return only first element of the hostname from all possible list.

    :return:
    u	localhostN(RDRERFRGReR;t	TypeErrorR (tret((s6/usr/lib/python2.7/site-packages/salt/utils/network.pytgenerate_minion_id�s
"

cC@sUtj|�j}|dkr*tj}n|dkrBtj}ntj|||�S(uE
    Return a socket object for the addr
    IP-version agnostic
    ii(RR\tversionRRR(R?ttypeR%RiR#((s6/usr/lib/python2.7/site-packages/salt/utils/network.pyt
get_socket�scC@s�tj�g}yktjtj�dtjtjtjtj�}x4|D],}t|�dkrI|j	|d�qIqIWWntj
k
r�nX|r�|dp�dS(u.
    Returns the fully qualified hostname
    iiiN(RRHRRCRRtSOL_TCPRNRORRPR (tltaddrinfotinfo((s6/usr/lib/python2.7/site-packages/salt/utils/network.pytget_fqhostname�s
cC@sOytj|�\}}}Wn,tk
rJ}tjd||�d}nX|S(u,
    Returns the hostname of a given IP
    u,salt.utils.network.ip_to_host(%r) failed: %sN(Rt
gethostbyaddrR!RQtdebugR (R(R^t	aliaslistt
ipaddrlisttexc((s6/usr/lib/python2.7/site-packages/salt/utils/network.pyt
ip_to_host�s
cC@sXy7ttj|dddd��tks0t�t}Wntjk
rSt}nX|S(u
    Returns a bool telling if the entity name is a reachable host (IPv4/IPv6/FQDN/etc).
    :param hostname:
    :return:
    i(RjRRRBtAssertionErrorR8RPR(tentity_nameRg((s6/usr/lib/python2.7/site-packages/salt/utils/network.pytis_reachable_host�s-

cC@st|�pt|�S(uR
    Returns a bool telling if the passed IP is a valid IPv4 or IPv6 address.
    (tis_ipv4tis_ipv6(R(((s6/usr/lib/python2.7/site-packages/salt/utils/network.pytis_ip�scC@s3ytj|�jdkSWntk
r.tSXdS(uS
    Returns a bool telling if the value passed to it was a valid IPv4 address
    iN(RR\Rit
ValueErrorR(R(((s6/usr/lib/python2.7/site-packages/salt/utils/network.pyRzs
cC@s3ytj|�jdkSWntk
r.tSXdS(uS
    Returns a bool telling if the value passed to it was a valid IPv6 address
    iN(RR\RiR}R(R(((s6/usr/lib/python2.7/site-packages/salt/utils/network.pyR{
s
cC@st|�pt|�S(uO
    Returns a bool telling if the passed string is an IPv4 or IPv6 subnet
    (tis_ipv4_subnettis_ipv6_subnet(tcidr((s6/usr/lib/python2.7/site-packages/salt/utils/network.pyt	is_subnetscC@s<y#d|ko!ttj|��SWntk
r7tSXdS(uG
    Returns a bool telling if the passed string is an IPv4 subnet
    u/N(tboolRtIPv4NetworkR!R(R�((s6/usr/lib/python2.7/site-packages/salt/utils/network.pyR~s#
cC@s<y#d|ko!ttj|��SWntk
r7tSXdS(uG
    Returns a bool telling if the passed string is an IPv6 subnet
    u/N(R�RtIPv6NetworkR!R(R�((s6/usr/lib/python2.7/site-packages/salt/utils/network.pyR(s#
uis_ipcC@s"t|d|�p!t|d|�S(uR
    Returns a bool telling if the passed IP is a valid IPv4 or IPv6 address.
    toptions(tis_ipv4_filtertis_ipv6_filter(R(R�((s6/usr/lib/python2.7/site-packages/salt/utils/network.pytis_ip_filter2scC@s|jS(N(t
is_private(tip_objRi((s6/usr/lib/python2.7/site-packages/salt/utils/network.pyt_ip_options_global:scC@s|jS(N(tis_multicast(R�Ri((s6/usr/lib/python2.7/site-packages/salt/utils/network.pyt_ip_options_multicast>scC@s|jS(N(R](R�Ri((s6/usr/lib/python2.7/site-packages/salt/utils/network.pyt_ip_options_loopbackBscC@s|jS(N(t
is_link_local(R�Ri((s6/usr/lib/python2.7/site-packages/salt/utils/network.pyt_ip_options_link_localFscC@s|jS(N(R�(R�Ri((s6/usr/lib/python2.7/site-packages/salt/utils/network.pyt_ip_options_privateJscC@s|jS(N(tis_reserved(R�Ri((s6/usr/lib/python2.7/site-packages/salt/utils/network.pyt_ip_options_reservedNscC@s|dkr|jStS(Ni(t
is_site_localR(R�Ri((s6/usr/lib/python2.7/site-packages/salt/utils/network.pyt_ip_options_site_localRscC@s|jS(N(tis_unspecified(R�Ri((s6/usr/lib/python2.7/site-packages/salt/utils/network.pyt_ip_options_unspecifiedXscC@s�itd6td6td6td6td6td6td6td6td	6td
6td6td6td
6td6td6}|s�tj	|�Sg|j
d�D]}|j�^q�}xB|j�D]4\}}||kr�|||�}|s�dSq�q�Wtj	|�S(Nuglobalu
link-localu	linklocalullu
link_localuloopbackulou	multicastuprivateupublicureservedu
site-localuslu
site_localuunspecifiedu,(R�R�R�R�R�R�R�R�Rt	text_typeRYRXtitemsR (R�RiR�toptions_fun_maptoptiontoptions_listtfuntfun_res((s6/usr/lib/python2.7/site-packages/salt/utils/network.pyt_ip_options\s2

(cC@s�|sd}n|dkrdSytj|�}Wn9tk
rmytj|�}Wqntk
ridSXnX|j|ks�dSt||d|�S(NiiR�(ii(R RR\R}tip_interfaceRiR�(R(RiR�R�((s6/usr/lib/python2.7/site-packages/salt/utils/network.pyt_is_ipv�s	

	uis_ipv4cC@s%t|dd|�}t|tj�S(u+
    Returns a bool telling if the value passed to it was a valid IPv4 address.

    ip
        The IP address.

    net: False
        Consider IP addresses followed by netmask.

    options
        CSV of options regarding the nature of the IP address. E.g.: loopback, multicast, private etc.
    iR�(R�t
isinstanceRtstring_types(R(R�t_is_ipv4((s6/usr/lib/python2.7/site-packages/salt/utils/network.pyR��suis_ipv6cC@s%t|dd|�}t|tj�S(u+
    Returns a bool telling if the value passed to it was a valid IPv6 address.

    ip
        The IP address.

    net: False
        Consider IP addresses followed by netmask.

    options
        CSV of options regarding the nature of the IP address. E.g.: loopback, multicast, private etc.
    iR�(R�R�RR�(R(R�t_is_ipv6((s6/usr/lib/python2.7/site-packages/salt/utils/network.pyR��scC@s�|dkrdSt|tjtjtjf�rDt||d|�St|tttj	f�r�g|D]6}t||d|�dk	rft||d|�^qfSdS(NiiR�(ii(R�RR�R�tbinary_typeR�RBttuplettypest
GeneratorTypeR (tvalueRiR�R?((s6/usr/lib/python2.7/site-packages/salt/utils/network.pyt_ipv_filter�s!
4uipv4cC@st|dd|�S(u6
    Filters a list and returns IPv4 values only.
    iR�(R�(R�R�((s6/usr/lib/python2.7/site-packages/salt/utils/network.pytipv4�suipv6cC@st|dd|�S(u6
    Filters a list and returns IPv6 values only.
    iR�(R�(R�R�((s6/usr/lib/python2.7/site-packages/salt/utils/network.pytipv6�suipaddrcC@sRt|d|�}t|d|�}|dks<|dkrF|pE|S||SdS(u4
    Filters and returns only valid IP objects.
    R�N(R�R�R (R�R�tipv4_objtipv6_obj((s6/usr/lib/python2.7/site-packages/salt/utils/network.pytipaddr�s

cC@s�d}|rK|dkr*t||�}qZ|dkrZt||�}qZnt||�}|sddSt|tttjf�s�|g}n|S(Nii(	R R�R�R�R�RBR�R�R�(R�R�Ritipaddr_filter_out((s6/usr/lib/python2.7/site-packages/salt/utils/network.pyt_filter_ipaddr�suip_hostcC@s�t|d|d|�}|s"dSt|tttjf�sWtjtj	|d��Sg|D]}tjtj	|��^q^S(uB
    Returns the interfaces IP address, e.g.: 192.168.0.1/28.
    R�RiNi(
R�R�RBR�R�R�RR�RR�(R�R�RiR�tip_a((s6/usr/lib/python2.7/site-packages/salt/utils/network.pytip_host�scC@s5gtj|dt�j�D]}tj|�^qS(Ntstrict(Rt
ip_networkRR_RR�(t
ip_addr_entryR((s6/usr/lib/python2.7/site-packages/salt/utils/network.pyt_network_hostssu
network_hostscC@sht|d|d|�}|s"dSt|tttjf�sKt|d�Sg|D]}t|�^qRS(u�
    Return the list of hosts within a network.

    .. note::

        When running this command with a large IPv6 network, the command will
        take a long time to gather all of the hosts.
    R�RiNi(R�R�RBR�R�R�R�(R�R�RiR�R�((s6/usr/lib/python2.7/site-packages/salt/utils/network.pyt
network_hostss
cC@stj|dt�jS(NR�(RR�Rt
num_addresses(R�((s6/usr/lib/python2.7/site-packages/salt/utils/network.pyt
_network_size(sunetwork_sizecC@sht|d|d|�}|s"dSt|tttjf�sKt|d�Sg|D]}t|�^qRS(u$
    Get the size of a network.
    R�RiNi(R�R�RBR�R�R�R�(R�R�RiR�R�((s6/usr/lib/python2.7/site-packages/salt/utils/network.pytnetwork_size,su	prefixlencC@sdt|�}|jd�r$d}n|jd�r<d}nd}|dkrXt|�Sd|SdS(	u7
    Returns the "natural" mask of an IPv4 address
    u11u24u1u16u8unetmasku/N(t
_ipv4_to_bitst
startswithtcidr_to_ipv4_netmask(R(tfmttbitstmask((s6/usr/lib/python2.7/site-packages/salt/utils/network.pytnatural_ipv4_netmask<s		
cC@s1djtjtj|jd�d�dd��S(u�
    Returns an IP network address padded with zeros.

    Ex: '192.168.3' -> '192.168.3.0'
        '10.209' -> '10.209.0.0'
    u.u0000ii(R
t	itertoolstislicetchainRY(R(((s6/usr/lib/python2.7/site-packages/salt/utils/network.pytrpad_ipv4_networkOs'cC@s�y0t|�}d|ko&dkns/dSWntk
rDdSXd}xotd�D]a}|rq|d7}n|dkr�|d7}|d8}qX|djd	d
d|�7}d}qXW|S(u!
    Returns an IPv4 netmask
    ii uiu.iu255u{0:d}iii(RR}RRS(t	cidr_bitstnetmasktidx((s6/usr/lib/python2.7/site-packages/salt/utils/network.pyR�Zs 




cC@stt|��S(uv
    Returns an IPv4 netmask from the integer representation of that mask.

    Ex. 0xffffff00 -> '255.255.255.0'
    (R�t_number_of_set_bits(tset_bits((s6/usr/lib/python2.7/site-packages/salt/utils/network.pyt#_number_of_set_bits_to_ipv4_netmaskrscC@s^||d?d@8}|d?d@|d@}|d?|d@}||d?7}||d?7}|d	@S(
u@
    Returns the number of bits that are set in a 32bit int
    iiUUUUii3333iiiii?((tx((s6/usr/lib/python2.7/site-packages/salt/utils/network.pyR�|sc@s�t�}�fd�}tjd�j|�}x�|D]�}d}t�}x||j�D]n}d|krqqYntjd|�}|r�|j�\}}	}
d|
jd�kr�t|d<n
t	|d<|	rY|	|d<qYqYn|j�}t
|�d	krYt|d
d	!�\�}|dd
}
�dkr�d|kr.|||�\}}}}�dkr�d|kr�t�|d<nt�}||d<||d<||d<|
|d<|dj
|�q��d
kr�d
|kr�t�|d
<nt�}||d<||d<||d<|d
j
|�q�q�d|krJt�|d<n|||�\}}}}|dj
i�d6|d6|d6|d6|
d6�~~~~q��jd�r�||d<q�qYqYW|r7|||<~~q7q7W|S(u�
    Uses ip to return a dictionary of interfaces with various information about
    each (up/down state, ip address, netmask, and hwaddr)
    c@s�d}d}d|kr0|jd�\}}n|}d}�dkr�tt|��}d|kr�||jd�d}q�n;�dkr�|}d|kr�||jd�d}q�n||||fS(	uc
        Return a tuple of ip, netmask, broadcast
        based on the current set of cols
        u/i uinetubrdiuinet6uscopeN(R RYR�Rtindex(R�tcolstbrdtscopeR(R�R�(ttype_(s6/usr/lib/python2.7/site-packages/salt/utils/network.pyt
parse_network�su
?
\du u-^\d*:\s+([\w.\-]+)(?:@)?([\w.\-]+)?:\s+<(.+)>uUPu,uupuparentiii����uinetuinet6u	secondaryuaddressunetmasku	broadcastulabelu	prefixlenuscopeutypeulinkuhwaddrN(uinetuinet6(tdictR6tcompileRYR t
splitlinesR7tgroupsR8RROR�RBRR�(RRgR�R�tgrouptifacetdataRcR7tparenttattrsR�R�tiflabelR�R�t	broadcastR�taddr_objtip_R�R�tscp((R�s6/usr/lib/python2.7/site-packages/salt/utils/network.pyt_interfaces_ip�st	
	


	



	





c	@s�t��tjd�}tjd�}tjjj�ritjd�}tjd�}tjd�}n-tjd�}tjd�}tjd�}tjd	�}tjd
�}tjd�}tjd�j|�}	x|	D]}
t�}d
�t}x)|
j	�D]}
|j
|
�}|j
|
�}|j
|
�}|j
|
�}|j|
�}|rs|jd��n|r|jd�|d<tjjj�rg}xR|djd�D]=}|j
t|�dkr�dj|�ndj|��q�Wdj|�|d<qn|r�d|kr4t�|d<nt�}|jd�|d<|j
|
�}|r�|jd�r�tt|jd�d��}n|jd�}||d<n|j
|
�}|r�|jd�|d<n|dj
|�n|r�t}n|r
d|kr!t�|d<nt�}|jd�pE|jd�|d<|j
|
�}|r�|jd�p||jd�|d<tjjj�s�|jd�p�|jd�}|d#k	r�|j�n||d<q�ntjjj�s|ddkr%|ddkr%|dj
|�q%q
q
W||d <��kr�tt|j��t��j�����<d|kr���dj��fd!�|dD��nd|kr���dj��fd"�|dD��q�n
|��<~q�W�S($u�
    Uses ifconfig to return a dictionary of interfaces with various information
    about each (up/down state, ip address, netmask, and hwaddr)
    u
^([^\s:]+)u3.*?(?:HWaddr|ether|address:|lladdr) ([0-9a-fA-F:]+)u2.*?(?:inet\s+)([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)(.*)u.*?(?:inet6 )([0-9a-fA-F:]+)u".*?(?:inet6 [0-9a-fA-F:]+/(\d+)).*u$.*?(?:inet addr:|inet [^\d]*)(.*?)\su/.*?(?:inet6 addr: (.*?)/|inet6 )([0-9a-fA-F:]+)uf.*?(?:inet6 addr: [0-9a-fA-F:]+/(\d+)|prefixlen (\d+))(?: Scope:([a-zA-Z]+)| scopeid (0x[0-9a-fA-F]))?u:.*?(?:Mask:|netmask )(?:((?:0x)?[0-9a-fA-F]{8})|([\d\.]+))uUPu!.*?(?:Bcast:|broadcast )([\d\.]+)u	
?
(?=\S)uiuhwaddru:iu0{0}u{0}uinetuaddressiunetmasku	broadcastuinet6u	prefixleniiuscopeu::iuupc3@s)|]}|��dkr|VqdS(uinetN((t.0R�(R�Rg(s6/usr/lib/python2.7/site-packages/salt/utils/network.pys	<genexpr>?sc3@s)|]}|��dkr|VqdS(uinet6N((R�R�(R�Rg(s6/usr/lib/python2.7/site-packages/salt/utils/network.pys	<genexpr>AsN(R�R6R�RDRERJtis_sunosRYRR�R7tsearchR�RRORSR
RBR�RR8R tlowerR�R4(Rtpifacetpmactpiptpip6tpmask6tpmasktpupdowntpbcastR�R�R�tupdownRctmifacetmmactmiptmip6tmupdownt
expand_mactchunkR�tmmasktmbcasttmmask6t	ipv6scope((R�Rgs6/usr/lib/python2.7/site-packages/salt/utils/network.pyt_interfaces_ifconfig�s�	
	;	
		""(
0/2
c
C@s`t�}tjjjd�}|r*dntjjjd�}|r�tjdj|�dt	dt	dtj
dtj�j�d}tjd	j|�dt	dt	dtj
dtj�j�d}t
d
jtjjj|�tjjj|���}n^|r\tjdj|�dt	dtj
dtj�j�d}ttjjj|��}n|S(
u<
    Obtain interface information for *NIX/BSD variants
    uipuifconfigu
{0} link showtshellt	close_fdststdouttstderriu
{0} addr showu{0}
{1}u{0} -aN(R�RDREtpathtwhichR t
subprocesstPopenRSR8tPIPEtSTDOUTtcommunicateR�RFtto_strR�(tifacestip_patht
ifconfig_pathtcmd1tcmd2tcmd((s6/usr/lib/python2.7/site-packages/salt/utils/network.pytlinux_interfacesHs6	!				cC@s�t�}tjd�}tjd�}tjd�}tjd�}tjd�}tjd�}tjd�j|�}x|D]}	t�}
d}t}x�|	j�D]�}
|j|
�}|j|
�}|j|
�}|j|
�}|j|
�}|r|jd	�}n|r/|jd	�|
d
<n|r�d|
krQt	�|
d<nt�}|jd	�|d<|jd
�}|jd
�r�t
|jd
��|d<n|j|
�}|r�|jd	�|d<n|
dj|�n|r�t}n|r�d|
krt	�|
d<nt�}|jd	�|d<|jd�}|jd
�|d<|jd�|d<|
dj|�q�q�W||
d<|
||<~
q�W|S(u�
    Uses ifconfig to return a dictionary of interfaces with various information
    about each (up/down state, ip address, netmask, and hwaddr)
    u
^([^\s:]+)u.*?address: ([0-9a-f:]+)u.*?inet [^\d]*(.*?)/([\d]*)\su..*?inet6 ([0-9a-f:]+)%([a-zA-Z0-9]*)/([\d]*)\suUPu.*?broadcast ([\d\.]+)u	
?
(?=\S)uiuhwaddruinetuaddressiunetmasku	broadcastuinet6iuscopeu	prefixlenuup(
R�R6R�RYRR�R7R�R�RBR�RR8(RRgR�R�R�R�R�R�R�R�R�R�R�RcR�R�R�R�R�R�R�R�R�((s6/usr/lib/python2.7/site-packages/salt/utils/network.pyt_netbsd_interfaces_ifconfigisb	
				

cC@s�ttj�d�td�kr)t�Stjjjd�}tj	dj
|�dtdtjdtj
�j�d}ttjjj|��S(	u�
    Obtain interface information for NetBSD >= 8 where the ifconfig
    output diverged from other BSD variants (Netmask is now part of the
    address)
    iu8.0uifconfigu{0} -aR�R�Ri(RRTtunameRRDRERRRRRSR8RRRRRFR(RR((s6/usr/lib/python2.7/site-packages/salt/utils/network.pytnetbsd_interfaces�s"	cC@s�t�}d}tjd�}x�|j�D]�}|s=q+n|jd�r~||j|�jd�}t|d<d}q+n|r+|j	dd�\}}|j
d�}|j
�}|r�|dkr�||d<q�|dkr6d|kr�t�|d<ni|jd�d
6dd6dd6}|dj
|�q�d|kr�d|kr^t�|d<ni|jd�d
6dd6}|dj
|�q�|dkr�||d<q�|dkr�|dk|d<q�q+q+WdS(u�
    Returns a dictionary of interfaces with various information about each
    (up/down state, ip address, netmask, and hwaddr)

    NOTE: This is not used by any function and may be able to be removed in the
    future.
    uadapter (\S.+):$uEthernetiuupu,u .uSubnet Maskunetmasku
IP AddressuIPv4 Addressuinetu(Preferred)uaddressu	broadcastuIPv6 Addressuinet6u	prefixlenuPhysical AddressuhwaddruMedia StateuMedia disconnectedN(u
IP AddressuIPv4 Address(R�R R6R�R�R�R�R�R8RYRXRBtrstripR(RR	R�tadapter_iface_regexRcR?tkeytval((s6/usr/lib/python2.7/site-packages/salt/utils/network.pyt_interfaces_ipconfig�sD	




c	C@sjtjjj��Rtj�}i}x8|jdd�D]$}t�||j<|j	rn|j	||jd<n|j
rKt||jd<x�|jD]�}d|krsd||jkr�g||jd<ni|d6|jd6}|j
rtd	�|j
D�d
�}|r||d<qn|jrXtd�|jD�d
�}|rX||d
<qXn||jdj|�nd|kr�d||jkr�g||jd<ni|d6}|j
r�td�|j
D�d
�}|r�||d<q�n|jr)td�|jD�d
�}|r)||d
<q)n||jdj|�q�q�Wq8t||jd<q8WWdQX|S(u:
    Obtain interface information for Windows systems
    t	IPEnablediuhwaddruupu.uinetuaddressulabelcs@s!|]}d|kr|VqdS(u.N((R�ti((s6/usr/lib/python2.7/site-packages/salt/utils/network.pys	<genexpr>�suu	broadcastcs@s!|]}d|kr|VqdS(u.N((R�R((s6/usr/lib/python2.7/site-packages/salt/utils/network.pys	<genexpr>sunetmasku:uinet6cs@s!|]}d|kr|VqdS(u:N((R�R((s6/usr/lib/python2.7/site-packages/salt/utils/network.pys	<genexpr>
scs@s!|]}d|kr|VqdS(u:N((R�R((s6/usr/lib/python2.7/site-packages/salt/utils/network.pys	<genexpr>sN(RDREtwinapitComtwmitWMIt!Win32_NetworkAdapterConfigurationR�tDescriptiont
MACAddressRR8t	IPAddresstDefaultIPGatewaytnexttIPSubnetRR(RR	R�R(titemR�R�((s6/usr/lib/python2.7/site-packages/salt/utils/network.pytwin_interfaces�sN		

		
		"cC@s=tjjj�rt�Stjjj�r2t�St�SdS(uS
    Return a dictionary of information about all the interfaces on the minion
    N(RDRERJt
is_windowsR&t	is_netbsdRR(((s6/usr/lib/python2.7/site-packages/salt/utils/network.pyt
interfacess
cC@s1tjdj||�dt�}tj|j�S(u+
    Return the address of the network
    u{0}/{1}R�(RR�RSRRR�tnetwork_address(R�R�tnet((s6/usr/lib/python2.7/site-packages/salt/utils/network.pyt
get_net_start#s!cC@sVd}x:|jd�D])}|tt|��djd�7}qWt|jd��S(uv
    Turns an IPv4 netmask into it's corresponding prefix length
    (255.255.255.0 -> 24 as in 192.168.1.10/24).
    uu.iiu0(RYtbinRtzfillROR(R�t
binary_strtoctet((s6/usr/lib/python2.7/site-packages/salt/utils/network.pytget_net_size+s'cC@s=|dk	r!dj||�}ntjtj|dt��S(u�
    Takes IP (CIDR notation supported) and optionally netmask
    and returns the network in CIDR-notation.
    (The IP can be any IP inside the subnet)
    u{0}/{1}R�N(R RSRR�RR�R(R�R�((s6/usr/lib/python2.7/site-packages/salt/utils/network.pytcalc_net6scC@sEdjg|jd�D](}tt|��djdd�^q�S(ub
    Accepts an IPv4 dotted quad and returns a string representing its binary
    counterpart
    uu.iiu0(R
RYR-Rtrjust(R�R�((s6/usr/lib/python2.7/site-packages/salt/utils/network.pyR�BscC@sat�}||j�kr%|tfSdj|dj|j���}tj|�d|fSdS(u
    If `iface` is available, return interface info and no error, otherwise
    return no info and log and return an error
    u2Interface "{0}" not in available interfaces: "{1}"u", "N(R)tkeysRRSR
RQterrorR (R�t
iface_infot	error_msg((s6/usr/lib/python2.7/site-packages/salt/utils/network.pyt_get_iface_infoJs	

cC@s�tjdj|�dtdtjdtj�j�d}|r�|jd�}t|�dkr�|dj	d	�j	�}|Snd
j|�}t
j|�|S(u�
    Return the hardware address (a.k.a. MAC address) for a given interface on AIX
    MAC address not available in through interfaces
    u(entstat -d {0} | grep 'Hardware Address'R�R�Riu iiu'uKInterface "{0}" either not available or does not contain a hardware address(RRRSR8RRRRYRORXRQR5(R�Rtcompstmac_addrR7((s6/usr/lib/python2.7/site-packages/salt/utils/network.pyt_hw_addr_aixZs	
cC@sXtjjj�rtSt|�\}}|tkrP|j|i�jdd�S|SdS(u�
    Return the hardware address (a.k.a. MAC address) for a given interface

    .. versionchanged:: 2016.11.4
        Added support for AIX

    uhwaddruN(RDRERJtis_aixR;R8Rtget(R�R6R5((s6/usr/lib/python2.7/site-packages/salt/utils/network.pythw_addrpscC@sBt|�\}}|tkr:|j|i�jdd�S|SdS(uH
    Return the details of `iface` or an error if it does not exist
    uinetuN(R8RR=(R�R6R5((s6/usr/lib/python2.7/site-packages/salt/utils/network.pyt	interface�scC@sbt|�\}}|tkrZ|j|i�jdd�}|rV|djdd�SdS|SdS(uH
    Return `iface` IPv4 addr or an error if `iface` does not exist
    uinetiuaddressuN(R8RR=R (R�R6R5tinet((s6/usr/lib/python2.7/site-packages/salt/utils/network.pytinterface_ip�s
uinetc
C@s�|dkrt�}npt|t�rli}xXtjt��D]%\}}||kr@|||<q@q@Wnit�j|i�|6}t�}|dkr�d}d}n5|dkr�d}d}ntj	dj
|��dSx�tj|�D]�}|j|g�}	|	jg|jd	g�D]!}
|
jd
�|kr"|
^q"�x{|	D]s}||kr�t
jdj
|d||��}nt
jdj
|d|��}|jsQ|j|j�qQqQWq�Wgt|�D]}tj|�^q�S(
u=
    Returns a list of subnets to which the host belongs
    uinetunetmaski uinet6u	prefixleni�u#Invalid proto {0} calling subnets()Nu	secondaryutypeu{0}/{1}uaddress(R R)R�RBRt	iteritemsR=tsetRQR5RSt
itervaluesR4RR�R]taddtnetworktsortedR�(
R%tinterfaces_R	RR�Rgtsubnett	dflt_cidrtip_infotaddrsR?tintfR+((s6/usr/lib/python2.7/site-packages/salt/utils/network.pyt_subnets�s6			A
&	cC@stdd|�S(uB
    Returns a list of IPv4 subnets to which the host belongs
    uinetRH(RN(R)((s6/usr/lib/python2.7/site-packages/salt/utils/network.pytsubnets�scC@s
td�S(uB
    Returns a list of IPv6 subnets to which the host belongs
    uinet6(RN(((s6/usr/lib/python2.7/site-packages/salt/utils/network.pytsubnets6�sc@s�ytj���Wn"tk
r7tjd��tSX|dkr`t�}|jt	��n!t
|ttf�s�|f}nt
�fd�|D��S(u\
    Returns True if host or (any of) addrs is within specified subnet, otherwise False
    uInvalid CIDR '%s'c3@s$|]}tj|��kVqdS(N(RR\(R�R%(R�(s6/usr/lib/python2.7/site-packages/salt/utils/network.pys	<genexpr>�sN(RR�R}RQR5RR R[R4t	ip_addrs6R�RBR�tany(R�R?((R�s6/usr/lib/python2.7/site-packages/salt/utils/network.pyt	in_subnet�s
	cC@swt�}t|t�r|nt�}|dkr<|}n_tgtj|�D]$\}}||krO||f^qO�}|s�tjdj	|��nx�tj
|�D]�}	|	j|g�}
|
jg|	jdg�D]!}|jd�|kr�|^q��xF|
D]>}t
j|jd��}|js9|r|j|�qqWq�Wgt|�D]}tj|�^q^S(u[
    Return the full list of IP adresses matching the criteria

    proto = inet|inet6
    uInterface {0} not found.u	secondaryutypeuaddressN(RCR�R�R)R RRBRQR5RSRDR=R4RR\R]RERGR�(R?tinclude_loopbacktinterface_dataR%RgR	t
target_ifacestktvRKRLR?((s6/usr/lib/python2.7/site-packages/salt/utils/network.pyt	_ip_addrs�s"			!A
cC@st|||d�S(u�
    Returns a list of IPv4 addresses assigned to the host. 127.0.0.1 is
    ignored, unless 'include_loopback=True' is indicated. If 'interface' is
    provided, then only IP addresses from that interface will be returned.
    uinet(RY(R?RTRU((s6/usr/lib/python2.7/site-packages/salt/utils/network.pyR[scC@st|||d�S(u�
    Returns a list of IPv6 addresses assigned to the host. ::1 is ignored,
    unless 'include_loopback=True' is indicated. If 'interface' is provided,
    then only IP addresses from that interface will be returned.
    uinet6(RY(R?RTRU((s6/usr/lib/python2.7/site-packages/salt/utils/network.pyRQsc	C@s�t|�dkrg}x�tddd�D]|}|||d!}gtddd�D]}|||d!^qU}|r�|jdj|��q+|jdj|��q+Wy9tjdj|��}|jr�t|j�S|j	SWqtj
k
r}tjdj|��|SXnyt
|d	�}Wntk
r>|SX|rwd
j|d?d@|d	?d@|d?d@|d@�Sd
j|d?d@|d	?d@|d?d@|d@�S(u�
    Convert a hex string to an ip, if a failure occurs the original hex is
    returned. If 'invert=True' assume that ip from /proc/net/<proto>
    i iiiu{0[3]}{0[2]}:{0[1]}{0[0]}u{0[0]}{0[1]}:{0[2]}{0[3]}u:u hex2ip - ipv6 address error: {0}iu{3}.{2}.{1}.{0}ii�u{0}.{1}.{2}.{3}(RORRRSRtIPv6AddressR
tipv4_mappedtstrt
compressedtAddressValueErrorRQR5RR}(	thex_iptinvertR(Rtip_partR�taddresstexthip((s6/usr/lib/python2.7/site-packages/salt/utils/network.pythex2ips:0	

cC@s�tjdd|�j�}|dd!d|d}tt|dd!d�dB�djd�|d}|d
kr�djtjd	|��SyHt	j
|d
t�}tdj|�d�}dj|||j
�SWntk
r�d
SXd
S(ug
    Convert a MAC address to a EUI64 identifier
    or, with prefix provided, a full IPv6 address
    u[.:-]uiiufffeiiu:u.{4}R�u0x{0}u{0}/{1}N(R6tsubR�thexRR.R R
tfindallRR�RRSt	prefixlenR!(tmactprefixteui64R+teuil((s6/usr/lib/python2.7/site-packages/salt/utils/network.pyt	mac2eui64;s5
c
C@s�i}x�ddgD]�}tjj|�rtjjj|d���}x�|D]�}tjjj|�}|j	�j
d�r�qMnt|�}tt
|��}||ddkrM||d=|||t|�<qMqMWWdQXqqW|S(uT
    Return a dict describing all active tcp connections as quickly as possible
    u
/proc/net/tcpu/proc/net/tcp6urbuslustateiN(RTRtisfileRDRERVRWRFRGRXR�t_parse_tcp_lineR#titerRO(Rgtstatftfp_Rctirettsl((s6/usr/lib/python2.7/site-packages/salt/utils/network.pyt
active_tcpPs
(cC@st|d�}|S(uN
    Return a set of remote ip addrs attached to the specified local port
    u
local_port(t_remotes_on(RRg((s6/usr/lib/python2.7/site-packages/salt/utils/network.pytlocal_port_tcpdscC@st|d�}|S(uQ
    Return a set of ip addrs the current host is connected to on given port
    uremote_port(Rw(RRg((s6/usr/lib/python2.7/site-packages/salt/utils/network.pytremote_port_tcplsc	
C@s�t|�}t||�}|dk	r+|St�}t}x�ddgD]�}tjj|�rGt}t	j
jj|d���}x�|D]�}t	j
j
j|�}|j�jd�r�q�nt|�}tt|��}||||kr�||ddkr�|j||d�q�q�WWdQXqGqGW|s�t	j
jj�rQt||�St	j
jj�rpt||�St	j
jj�r�t||�St	j
jj�r�t||�St	j
jj�r�t||�St	j
jj �r�t!||�St"||�S|S(	u9
    Return a set of ip addrs active tcp connections
    u
/proc/net/tcpu/proc/net/tcp6uruslustateiuremote_addrN(#Rt_netlink_tool_remote_onR RCRRTRRoR8RDRERVRWRFRGRXR�RpR#RqRERJR�t_sunos_remotes_ont
is_freebsdt_freebsd_remotes_onR(t_netbsd_remotes_ont
is_openbsdt_openbsd_remotes_onR't_windows_remotes_onR<t_aix_remotes_ont_linux_remotes_on(	Rt	which_endRgtproc_availableRrRsRcRtRu((s6/usr/lib/python2.7/site-packages/salt/utils/network.pyRwtsB	
()






cC@s�i}|j�j�}|djd�}i||<|djd�\}}|djd�\}}t|t�||d<t|d�||d<t|t�||d<t|d�||d	<t|d
d�||d<|S(uR
    Parse a single line from the contents of /proc/net/tcp or /proc/net/tcp6
    iu:iiu
local_addriu
local_porturemote_addruremote_portiustate(RXRYRReR8R(RcRgR9Rutl_addrtl_porttr_addrtr_port((s6/usr/lib/python2.7/site-packages/salt/utils/network.pyRp�s
cC@skt�}t}ytjddg�}Wn5tjk
rNtjd��ntk
r_d
SXt	j
jj|�j
d�}x�|D]�}d|kr�t}q�nd|kr�q�n|j
�}|djdd	�\}}	|d
jdd	�\}
}|dkrt|�|krq�n|dkrAt|	�|krAq�n|j|
�q�W|tkrgd
}n|S(u=
    Returns set of ipv4 host addresses of remote established connections
    on local or remote tcp port.

    Parses output of shell 'ss' to get connections

    [root@salt-master ~]# ss -ant
    State      Recv-Q Send-Q               Local Address:Port                 Peer Address:Port
    LISTEN     0      511                              *:80                              *:*
    LISTEN     0      128                              *:22                              *:*
    ESTAB      0      0                      127.0.0.1:56726                  127.0.0.1:4505
    ussu-antu	Failed ssu
uAddress:PortuESTABiu:iiuremote_portu
local_portN(RCRRtcheck_outputtCalledProcessErrorRQR5tOSErrorR RDRERFRRYR8trsplitRRE(RR�tremotestvalidR�tlinesRctchunkst
local_hostt
local_porttremote_hosttremote_port((s6/usr/lib/python2.7/site-packages/salt/utils/network.pyRz�s6
	


	cC@s-t�}ytjddddg�}Wn$tjk
rNtjd��nXtjjj	|�j
d�}x�|D]�}d|kr�qtn|j
�}|djd	d
�\}}|d
jd	d
�\}	}
|dkr�t|
�|kr�qtn|dkrt|�|krqtn|j
|	�qtW|S(
uf
    SunOS specific helper function.
    Returns set of ipv4 host addresses of remote established connections
    on local or remote tcp port.

    Parses output of shell 'netstat' to get connections

    [root@salt-master ~]# netstat -f inet -n
    TCP: IPv4
       Local Address        Remote Address    Swind Send-Q Rwind Recv-Q    State
       -------------------- -------------------- ----- ------ ----- ------ -----------
       10.0.0.101.4505      10.0.0.1.45329       1064800      0 1055864      0 ESTABLISHED
       10.0.0.101.4505      10.0.0.100.50798     1064800      0 1055864      0 ESTABLISHED
    unetstatu-fuinetu-nuFailed netstatu
uESTABLISHEDiu.iuremote_portu
local_port(RCRR�R�RQR5RDRERFRRYR�RRE(RR�R�R�R�RcR�R�R�R�R�((s6/usr/lib/python2.7/site-packages/salt/utils/network.pyR{�s&	

cC@s�t|�}t�}y1tjjjdj|��}tj|�}Wn2tj	k
rz}t
jdj|j���nXtjj
j|�jd�}x�|D]�}|j�}|s�q�nd|dkr�q�nt|�dkr�q�n|d}	|d}
|	jd	�\}}|
jd	�\}
}|d
krNt|�|krNq�n|dkrrt|�|krrq�n|j|
�q�W|S(u�
    Returns set of ipv4 host addresses of remote established connections
    on local tcp port port.

    Parses output of shell 'sockstat' (FreeBSD)
    to get connections

    $ sudo sockstat -4
    USER    COMMAND     PID     FD  PROTO  LOCAL ADDRESS    FOREIGN ADDRESS
    root    python2.7   1456    29  tcp4   *:4505           *:*
    root    python2.7   1445    17  tcp4   *:4506           *:*
    root    python2.7   1294    14  tcp4   127.0.0.1:11813  127.0.0.1:4505
    root    python2.7   1294    41  tcp4   127.0.0.1:61115  127.0.0.1:4506

    $ sudo sockstat -4 -c -p 4506
    USER    COMMAND     PID     FD  PROTO  LOCAL ADDRESS    FOREIGN ADDRESS
    root    python2.7   1294    41  tcp4   127.0.0.1:61115  127.0.0.1:4506
    usockstat -4 -c -p {0}u'Failed "sockstat" with returncode = {0}u
uCOMMANDiii����i����u:ulocaluremote(RRCRDREtargstshlex_splitRSRR�R�RQR5t
returncodeRFRRYRORE(RR�R�RR�RcR�RcR�tlocaltremotetlhosttlporttrhosttrport((s6/usr/lib/python2.7/site-packages/salt/utils/network.pyR}s6	


cC@s�t|�}t�}y1tjjjdj|��}tj|�}Wn2tj	k
rz}t
jdj|j���nXtjj
j|�jd�}x|D]�}|j�}|s�q�nd|dkr�q�nt|�dkr�q�n|djd�}	|	j�}
dj|	�}|d	jd�}|j�}
dj|�}|d
krlt|
�|krlq�n|dkr�t|
�|kr�q�n|j|�q�W|S(u�
    Returns set of ipv4 host addresses of remote established connections
    on local tcp port port.

    Parses output of shell 'sockstat' (NetBSD)
    to get connections

    $ sudo sockstat -4 -n
    USER    COMMAND     PID     FD  PROTO  LOCAL ADDRESS    FOREIGN ADDRESS
    root    python2.7   1456    29  tcp    *.4505           *.*
    root    python2.7   1445    17  tcp    *.4506           *.*
    root    python2.7   1294    14  tcp    127.0.0.1.11813  127.0.0.1.4505
    root    python2.7   1294    41  tcp    127.0.0.1.61115  127.0.0.1.4506

    $ sudo sockstat -4 -c -n -p 4506
    USER    COMMAND     PID     FD  PROTO  LOCAL ADDRESS    FOREIGN ADDRESS
    root    python2.7   1294    41  tcp    127.0.0.1.61115  127.0.0.1.4506
    usockstat -4 -c -n -p {0}u'Failed "sockstat" with returncode = {0}u
uCOMMANDiiiu.iulocaluremote(RRCRDRER�R�RSRR�R�RQR5R�RFRRYROtpopR
RE(RR�R�RR�RcR�RcR�R�R�R�R�R�R�((s6/usr/lib/python2.7/site-packages/salt/utils/network.pyR~As:	
cC@st�}ytjdddg�}Wn$tjk
rKtjd��nX|jd�}x�|D]�}d|krzqbn|j�}|djdd	�\}}|d
jdd	�\}	}
|dkr�t|
�|kr�qbn|dkrt|�|krqbn|j	|	�qbW|S(
u
    OpenBSD specific helper function.
    Returns set of ipv4 host addresses of remote established connections
    on local or remote tcp port.

    Parses output of shell 'netstat' to get connections

    $ netstat -nf inet
    Active Internet connections
    Proto   Recv-Q Send-Q  Local Address          Foreign Address        (state)
    tcp          0      0  10.0.0.101.4505        10.0.0.1.45329         ESTABLISHED
    tcp          0      0  10.0.0.101.4505        10.0.0.100.50798       ESTABLISHED
    unetstatu-nfuinetuFailed netstatu
uESTABLISHEDiu.iiuremote_portu
local_port(
RCRR�R�RQR5RYR�RRE(RR�R�R�R�RcR�R�R�R�R�((s6/usr/lib/python2.7/site-packages/salt/utils/network.pyR�|s&	

cC@s't�}ytjddg�}Wn$tjk
rHtjd��nXtjjj	|�j
d�}x�|D]�}d|kr�qnn|j
�}|djdd�\}}|djdd�\}	}
|d	kr�t|
�|kr�qnn|d
krt|�|krqnn|j
|	�qnW|S(u�
    Windows specific helper function.
    Returns set of ipv4 host addresses of remote established connections
    on local or remote tcp port.

    Parses output of shell 'netstat' to get connections

    C:\>netstat -n

    Active Connections

       Proto  Local Address          Foreign Address        State
       TCP    10.2.33.17:3007        130.164.12.233:10123   ESTABLISHED
       TCP    10.2.33.17:3389        130.164.30.5:10378     ESTABLISHED
    unetstatu-nuFailed netstatu
uESTABLISHEDiu:iuremote_portu
local_port(RCRR�R�RQR5RDRERFRRYR�RRE(RR�R�R�R�RcR�R�R�R�R�((s6/usr/lib/python2.7/site-packages/salt/utils/network.pyR��s&	

cC@s�t�}y(tjddj|�ddg�}WnRtjk
r�}|jdkrftjd�|Stjdj|j���nXt	j
jj|�j
d�}x�|D]�}|j
�}|s�q�nd	|d
kr�q�nd|dkr�q�n|d
j
d�\}}	|jdd�\}
}|	jdd�\}}
|dkrbt|
�|krbq�n|dkr�t|�|kr�q�n|j|jd��q�W|S(u�
    Linux specific helper function.
    Returns set of ip host addresses of remote established connections
    on local tcp port port.

    Parses output of shell 'lsof'
    to get connections

    $ sudo lsof -iTCP:4505 -n
    COMMAND   PID USER   FD   TYPE             DEVICE SIZE/OFF NODE NAME
    Python   9971 root   35u  IPv4 0x18a8464a29ca329d      0t0  TCP *:4505 (LISTEN)
    Python   9971 root   37u  IPv4 0x18a8464a29b2b29d      0t0  TCP 127.0.0.1:4505->127.0.0.1:55703 (ESTABLISHED)
    Python  10152 root   22u  IPv4 0x18a8464a29c8cab5      0t0  TCP 127.0.0.1:55703->127.0.0.1:4505 (ESTABLISHED)
    Python  10153 root   22u  IPv4 0x18a8464a29c8cab5      0t0  TCP [fe80::249a]:4505->[fe80::150]:59367 (ESTABLISHED)

    ulsofu-iTCP:{0:d}u-nu-Piu5"lsof" returncode = 1, likely no active TCP sessions.u#Failed "lsof" with returncode = {0}u
uCOMMANDiuESTABLISHEDi����iu->u:uremote_portu
local_portu[](RCRR�RSR�R�RQRRR5RDRERFRRYR�RRERX(RR�R�R�RcR�RcR�R�R�t_R�R�R�((s6/usr/lib/python2.7/site-packages/salt/utils/network.pyR��s8	"

cC@s-t�}ytjddddg�}Wn$tjk
rNtjd��nXtjjj	|�j
d�}x�|D]�}d|kr�qtn|j
�}|djd	d
�\}}|djd	d
�\}	}
|dkr�t|
�|kr�qtn|d
krt|�|krqtn|j
|	�qtW|S(uk
    AIX specific helper function.
    Returns set of ipv4 host addresses of remote established connections
    on local or remote tcp port.

    Parses output of shell 'netstat' to get connections

    root@la68pp002_pub:/opt/salt/lib/python2.7/site-packages/salt/modules# netstat -f inet -n
    Active Internet connections
    Proto Recv-Q Send-Q  Local Address          Foreign Address        (state)
    tcp4       0      0  172.29.149.95.50093    209.41.78.13.4505      ESTABLISHED
    tcp4       0      0  127.0.0.1.9514         *.*                    LISTEN
    tcp4       0      0  127.0.0.1.9515         *.*                    LISTEN
    tcp4       0      0  127.0.0.1.199          127.0.0.1.32779        ESTABLISHED
    tcp4       0      0  127.0.0.1.32779        127.0.0.1.199          ESTABLISHED
    tcp4       0     40  172.29.149.95.22       172.29.96.83.41022     ESTABLISHED
    tcp4       0      0  172.29.149.95.22       172.29.96.83.41032     ESTABLISHED
    tcp4       0      0  127.0.0.1.32771        127.0.0.1.32775        ESTABLISHED
    tcp        0      0  127.0.0.1.32775        127.0.0.1.32771        ESTABLISHED
    tcp4       0      0  127.0.0.1.32771        127.0.0.1.32776        ESTABLISHED
    tcp        0      0  127.0.0.1.32776        127.0.0.1.32771        ESTABLISHED
    tcp4       0      0  127.0.0.1.32771        127.0.0.1.32777        ESTABLISHED
    tcp        0      0  127.0.0.1.32777        127.0.0.1.32771        ESTABLISHED
    tcp4       0      0  127.0.0.1.32771        127.0.0.1.32778        ESTABLISHED
    tcp        0      0  127.0.0.1.32778        127.0.0.1.32771        ESTABLISHED
    unetstatu-fuinetu-nuFailed netstatu
uESTABLISHEDiu.iiuremote_portu
local_port(RCRR�R�RQR5RDRERFRRYR�RRE(RR�R�R�R�RcR�R�R�R�R�((s6/usr/lib/python2.7/site-packages/salt/utils/network.pyR�s&	

ugen_macuAC:DE:48cC@s:dj|tjdd�tjdd�tjdd��S(u�
    Generates a MAC address with the defined OUI prefix.

    Common prefixes:

     - ``00:16:3E`` -- Xen
     - ``00:18:51`` -- OpenVZ
     - ``00:50:56`` -- VMware (manually generated)
     - ``52:54:00`` -- QEMU/KVM
     - ``AC:DE:48`` -- PRIVATE

    References:

     - http://standards.ieee.org/develop/regauth/oui/oui.txt
     - https://www.wireshark.org/tools/oui-lookup.html
     - https://en.wikipedia.org/wiki/MAC_address
    u{0}:{1:02X}:{2:02X}:{3:02X}ii�(RStrandomtrandint(Rk((s6/usr/lib/python2.7/site-packages/salt/utils/network.pytgen_mac2s	umac_str_to_bytesc@s�t��dkrn=t��dkrF�d}�j|d��ntd���fd�tddd�D�}tjr�t|�Sdjd	�|D��S(
u�
    Convert a MAC address string into bytes. Works with or without separators:

    b1 = mac_str_to_bytes('08:00:27:13:69:77')
    b2 = mac_str_to_bytes('080027136977')
    assert b1 == b2
    assert isinstance(b1, bytes)
    iiiuuInvalid MAC addressc3@s)|]}t�||d!d�VqdS(iiN(R(R�ts(tmac_str(s6/usr/lib/python2.7/site-packages/salt/utils/network.pys	<genexpr>\sitcs@s|]}t|�VqdS(N(tchr(R�R�((s6/usr/lib/python2.7/site-packages/salt/utils/network.pys	<genexpr>]s(ROtreplaceR}RRtPY3tbytesR
(R�tseptchars((R�s6/usr/lib/python2.7/site-packages/salt/utils/network.pytmac_str_to_bytesKs

"cC@s#yt�Wntk
rnXdS(u:
    issue #21397: force glibc to re-read resolv.conf
    N(tres_initt	NameError(((s6/usr/lib/python2.7/site-packages/salt/utils/network.pytrefresh_dns`s
u	dns_checkcC@s(g}|rtjn|tkr*tjntj}y5t�tj|||tj�}t||�}WnHt	k
r�dj
|�}tddd|��ntjk
r�nX|sdj
|�}|r�t
jj�r�tj|�nt��ntddd|��nt
jjj|d�S(u�
    Return an ip address resolved by dns in a format usable in URLs (ipv6 in brackets).
    Obeys system preference for IPv4/6 address resolution - this can be overridden by
    the ipv6 flag. Tries to connect to the address before considering it useful. If no
    address can be reached, the first one resolved is used as a fallback.
    Does not exit on failure, raises an exception.
    uIAttempt to resolve address '{0}' failed. Invalid or unresolveable addresstcodei*tmsgu/DNS lookup or connection check of '{0}' failed.i(RRRRRR�RRt_test_addrsRfRSR	R5RDRQtis_console_configuredRREtzeromqt
ip_bracket(R?RtsafeR�R[R#Rnterr((s6/usr/lib/python2.7/site-packages/salt/utils/network.pyt	dns_checkks&	-
cC@s�g}x�|D]�}|d}|dd}||kr=q
n|j|�y@tj|tj�}|j||f�|j�|g}PWq
tjk
r�q
Xq
W|S(uj
    Attempt to connect to all addresses, return one if it succeeds.
    Otherwise, return all addrs.
    ii(RRRtconnecttcloseR5(RnRR[tat	ip_familytip_addrR�((s6/usr/lib/python2.7/site-packages/salt/utils/network.pyR��s 



	cC@s�d\}}|}|ddkr�d|kr2|jd�jdd�\}}tj|�j}|ddkr�t|jd��}q�t|�dkr�tdj	||���q�q2nu|j
d�dkr,|jd�\}}}yt|�}Wq2tk
r(}tj
d||�|�q2Xn|}y1t|tj�sbtj|�j}|}nWn[tk
r�tjd|�|t|�kr�tj
d	|�td
j	|���q�nX||fS(
u�
    Takes a string argument specifying host or host:port.

    Returns a (hostname, port) or (ip_address, port) tuple. If no port is given,
    the second (port) element of the returned tuple will be None.

    host:port argument, for example, is accepted in the forms of:
      - hostname
      - hostname:1234
      - hostname.domain.tld
      - hostname.domain.tld:5678
      - [1234::5]:5678
      - 1234::5
      - 10.11.12.13:4567
      - 10.11.12.13
    iu[u]iu:u!found ambiguous "{}" port in "{}"u1host_port "%s" port value "%s" is not an integer.u2"%s" Not an IP address? Assuming it is a hostname.ubad hostname: "%s"ubad hostname: "{}"N(NN(R tlstripR�RRZR]RROR}RStcountt	partitionRQR5R�t_BaseAddressR\RrR(t	host_portRRt_s_t_hostport_separator_t_e_thost_ip((s6/usr/lib/python2.7/site-packages/salt/utils/network.pytparse_host_port�s8!!


(�R>t
__future__RRRR�RTR6R�RtloggingRJR�RtstringRRtsalt.extRtsalt.ext.six.movesRRtsalt.utils.winapiRDtImportErrortsalt.utils.argstsalt.utils.filestsalt.utils.pathtsalt.utils.platformtsalt.utils.stringutilstsalt.utils.zeromqtsalt._compatRtsalt.exceptionsRR	tsalt.utils.decorators.jinjaR
tsalt.utils.versionsRRER'Rt	getLoggerR<RQtctypestctypes.utiltcdlltLoadLibrarytutiltfind_librarytlibct
__res_initR�R�tAttributeErrorRfRRR+ReRhRRkRpRvRyR|RzR{R�R~RR R�R�R�R�R�R�R�R�R�R�R�R�R�R�R�R�R�R�R�R�R�R�R�R�R�R�R�R�R�R�RRRRR&R)R,R1R2R�R8R;R>R?RARNRORPRSRRYR[RQReRnRvRxRyRwRpRzR{R}R~R�R�R�R�R�R�R�R�R�R�(((s6/usr/lib/python2.7/site-packages/salt/utils/network.pyt<module>s

					I	
					
	
		
	
									$													
		]	`	!	<		1	.									
(			'				,		-	&	<	;	%	&	9	2			"	

Zerion Mini Shell 1.0