Your IP : 216.73.216.52


Current Path : /usr/lib/python3/dist-packages/landscape/lib/__pycache__/
Upload File :
Current File : //usr/lib/python3/dist-packages/landscape/lib/__pycache__/network.cpython-38.pyc

U

/�
b\%�@s�ddlmZddlZddlZddlZddlZddlZddlZddlZddl	m
Z
ddgZdZdZ
dZd	d
�Zdd�Zd
d�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zd%dd�Zd&d d�Zd!d"�Zd#d$�ZdS)'�)�absolute_importN)�long�get_active_device_info�get_network_traffici�iF��cCst�d�dkS)z>Returns C{True} if the platform is 64-bit, otherwise C{False}.�l�)�structZcalcsize�r
r
�7/usr/lib/python3/dist-packages/landscape/lib/network.py�is_64srcCs|d@S)z�Returns C{True} if the interface is up, otherwise C{False}.

    @param flags: the integer value of an interface's flags.
    @see /usr/include/linux/if.h for the meaning of the flags.
    rr
)�flagsr
r
r�is_upsrccsbt��D]T}t�|�}|�tjig�d�d�}|�tjig�d�d�}|sR|r||fVqdS)a}Generator yields (active network interface name, address data) tuples.

    Address data is formatted exactly like L{netifaces.ifaddresses}, e.g.::

        ('eth0', {
            AF_LINK: [
                {'addr': '...', 'broadcast': '...'}, ],
            AF_INET: [
                {'addr': '...', 'broadcast': '...', 'netmask': '...'},
                {'addr': '...', 'broadcast': '...', 'netmask': '...'},
                ...],
            AF_INET6: [
                {'addr': '...', 'netmask': '...'},
                {'addr': '...', 'netmask': '...'},
                ...], })

    Interfaces with no IP address are ignored.
    r�addrN)�	netifacesZ
interfaces�ifaddresses�get�AF_INET�AF_INET6)�	interfacerZ	inet_addrZ
inet6_addrr
r
r�get_active_interfaces&s
rcCsNi}tj|kr|tj|tj<tj|krJdd�|tjD�}|rJ||tj<|S)aReturn all IP addresses of an interfaces.

    Returns the same structure as L{ifaddresses}, but filtered to keep
    IP addresses only.

    @param ifaddresses: a dict as returned by L{netifaces.ifaddresses} or
        the address data in L{get_active_interfaces}'s output.
    cSsg|]}|d�d�s|�qS)rzfe80:)�
startswith)�.0rr
r
r�
<listcomp>Ps�z$get_ip_addresses.<locals>.<listcomp>)rrr)r�resultsZglobal_addrsr
r
r�get_ip_addressesBs	


rcCs|tjd�dd�S)z�Return the broadcast address associated to an interface.

    @param ifaddresses: a dict as returned by L{netifaces.ifaddresses} or
        the address data in L{get_active_interfaces}'s output.
    rZ	broadcastz0.0.0.0�rrr�rr
r
r�get_broadcast_addressXsrcCs|tjd�dd�S)z�Return the network mask associated to an interface.

    @param ifaddresses: a dict as returned by L{netifaces.ifaddresses} or
        the address data in L{get_active_interfaces}'s output.
    r�netmask�rrr
r
r�get_netmaskasr!cCs|tjddS)z�Return the first IPv4 address associated to the interface.

    @param ifaddresses: a dict as returned by L{netifaces.ifaddresses} or
        the address data in L{get_active_interfaces}'s output.
    rr)rrrr
r
r�get_ip_addressjsr"cCs$tj|kr |tjd�dd�SdS)aG
    Return the hardware MAC address for an interface in human friendly form,
    ie. six colon separated groups of two hexadecimal digits, if available;
    otherwise an empty string.

    @param ifaddresses: a dict as returned by L{netifaces.ifaddresses} or
        the address data in L{get_active_interfaces}'s output.
    rrr )rZAF_LINKrrr
r
r�get_mac_addressss	
r#c
Cs:t�|��tt�d|dd���}t�d|dd��dS)z�Return the integer value of the interface flags for the given interface.

    @param sock: a socket instance.
    @param interface: The name of the interface.
    @see /usr/include/linux/if.h for the meaning of the flags.
    Z256sN��H��r)�fcntl�ioctl�fileno�SIOCGIFFLAGSr	�pack�unpack)�sockr�datar
r
r�	get_flags�s�r0��loTFc
Csg}z�t�tjtjtj�}t�D]�\}}||kr2q |r@d|kr@q |rNd|krNq t||���}t|�sfq d|i}	||	d<t||���\}
}|
|	d<||	d<t	|�}|r�||	d<t
j|kr�t|�|	d<t|�|	d	<t
|�|	d
<t|�|	d<t
j|ks�|r |�|	�q W5~X|S)zp
    Returns a dictionary containing information on each active network
    interface present on a machine.
    �.�:rr
�speed�duplex�ip_addressesZ
ip_addressZmac_addressZbroadcast_addressr)�socketr�
SOCK_DGRAM�
IPPROTO_IPrr0�encoder�get_network_interface_speedrrr"r#rr!�append)
Zskipped_interfacesZ	skip_vlanZ
skip_aliasZextendedrr.rrr
Zinterface_infor5r6r7r
r
rr�sJ��
��
/proc/net/devc	Cs�t|d��}|��}W5QRX|d�d�\}}}dd�|��D�}|�dd�|��D��i}|dd�D]@}d	|krzql|�d	�\}	}
|	��}	tt|tt|
�����||	<ql|S)
ze
    Retrieves an array of information regarding the network activity per
    network interface.
    �rr�|cSsg|]}d|�qS)zrecv_%sr
�r�columnr
r
rr�sz'get_network_traffic.<locals>.<listcomp>cSsg|]}d|�qS)zsend_%sr
rAr
r
rr�s�Nr4)	�open�	readlines�split�extend�strip�dict�zip�mapr)Zsource_fileZnetdev�lines�_Zreceive_columnsZtransmit_columns�columnsZdevices�lineZdevicer/r
r
rr�scCsLt��}d|krHt�t��dtjtjtjtj�dd}d|krHt��}|S)a
    Return the current fqdn of the machine, trying hard to return a meaningful
    name.

    In particular, it means working against a NetworkManager bug which seems to
    make C{getfqdn} return localhost6.localdomain6 for machine without a domain
    since Maverick.
    Z	localhostNr�)r8ZgetfqdnZgetaddrinfoZgethostnamerr9r:ZAI_CANONNAME)Zfqdnr
r
r�get_fqdn�s	���rQc	
Cs�t�dtd�}t�d|�}t�d||��d�}d}z*t�|t|�|��}t�	d|�\}}Wnbt
tfk
r�}z@|jtj
kr�t�d�n|jtjkr�|jtjkr�|�d}d	}W5d
}~XYnX|dkr�d}|dkr�d	}t|�}||fS)
a�
    Return the ethernet device's advertised link speed.

    The return value can be one of:
        * 10, 100, 1000, 2500, 10000: The interface speed in Mbps
        * -1: The interface does not support querying for max speed, such as
          virtio devices for instance.
        * 0: The cable is not connected to the interface. We cannot measure
          interface speed, but could if it was plugged in.
    ZI39ss'�BZ16sPr���Z12xHB28xzECould not determine network interface speed, operation not permitted.FNi���)r	r,�ETHTOOL_GSET�arrayZbuffer_infor(r)�SIOCETHTOOLZtostringr-�IOError�OSError�errnoZEPERM�logging�warnZ
EOPNOTSUPPZEINVAL�bool)	r.Zinterface_nameZ
cmd_structZ
status_cmdZpackedr5�resr6�er
r
rr<�s*r<)r1TTF)r>)Z
__future__rrVr(r8r	rZr[rZtwisted.python.compatr�__all__r+rWrUrrrrrr!r"r#r0rrrQr<r
r
r
r�<module>s:				�
-