ok

Mini Shell

Direktori : /opt/imunify360/venv/lib64/python3.11/site-packages/im360/utils/__pycache__/
Upload File :
Current File : //opt/imunify360/venv/lib64/python3.11/site-packages/im360/utils/__pycache__/net.cpython-311.pyc

�

g���ddlZddlZddlZddlmZddlmZmZmZm	Z	m
Z
mZmZddl
mZmZmZmZddlZddlmZddlmZmZeje��Zejdej��Zd\ZZZ d	\Z!Z"ee	efZ#d
Z$ddeefd�Z%d
eeee
ffd�Z&d�Z'ed���d���Z(de)fd�Z*d�Z+deee
ffd�Z,dee	efd
ee)e)e)ffd�Z-de)de)de)d
e#fd�Z.de/d
ede	effd�Z0dS) �N)�	lru_cache)�
IPV4LENGTH�
IPV6LENGTH�IPv4Address�IPv4Network�IPv6Address�IPv6Network�
ip_network)�Iterable�Optional�Tuple�Union)�get_kernel_module_parameter)�IP�	IPVersions^nameserver ([\w.:]+))�tcp�udp�all)�in�outz/etc/resolv.conf�
ip_versionc#�K�	ttd��5}|���}ddd��n#1swxYwYn#t$rgcYSwxYwt�|��D]K}|�d��}tj|��r |�tj	|��|ks|�|V��LdS)N�rb�ascii)
�open�RESOLV_CONF_FILE�read�OSError�DNS_IP_TEMPLATE�findall�decoder�is_valid_ip�type_of)r�f�content�ips    �D/opt/imunify360/venv/lib/python3.11/site-packages/im360/utils/net.py�local_dns_from_resolv_confr(!s�����
�"�D�
)�
)�	�Q��f�f�h�h�G�	�	�	�	�	�	�	�	�	�	�	����	�	�	�	��������	�	�	������%�%�g�.�.����
�Y�Y�w�
�
��
�>�"���	��&�2�:�b�>�>�Z�+G�+G��#������
�s.�A�:�A�>�A�>�A�A�A�returnc#�HK�tj�����D]y}|D]t}|jtjkrt
|j��V��.|jtjkr1t|j�
dd���d��V��u�zdS)z8Return a list of IP address assigned to local interfaces�%�)�maxsplitrN)�psutil�net_if_addrs�values�family�socket�AF_INETr�address�AF_INET6r�split)�ipsr&s  r'�local_ip_addressesr81s������"�$�$�+�+�-�-�H�H���	H�	H�B��y�F�N�*�*�!�"�*�-�-�-�-�-�-���f�o�-�-�"�"�*�"2�"2�3��"2�"C�"C�A�"F�G�G�G�G�G��
	H�H�H�c��|ttfvsJ�|tkrd}nd}td�tj|��D����S)zZ
    Return listening ports for ipv4 services

    :param proto: tcp/udp
    :return:
    �tcp4�udp4c3�|K�|]7}|jddk�|jtjk�(|jdV��8dS)rz	127.0.0.1r,N)�laddr�statusr.�CONN_LISTEN)�.0�cs  r'�	<genexpr>z"listening_ports.<locals>.<genexpr>JsT������
�
�G�A�J�+�%�%�!�(�f�6H�*H�*H�	
���
�*H�*H�*H�*H��r9)�TCP�UDP�setr.�net_connections)�proto�kinds  r'�listening_portsrJ=sg���S�#�J�������|�|����������'��-�-������r9r,)�maxsizec��	tdd���}|dkS#t$r%}t�|��Yd}~dSd}~wwxYw)z�
    Checks whether ipv6 kernel module is not disabled or absent
    https://www.kernel.org/doc/Documentation/networking/ipv6.txt
    :return:
    �ipv6�disable)�module_name�	parameter�0NF)r�
ValueError�logger�warning)rN�es  r'�is_ipv6_enabledrVQsl���-��)�
�
�
��
�#�~����������q�����u�u�u�u�u�����	���s��
A�A�Ar&c�h�t�|�ddd���dd���S)N��bigT��signedF)�int�
from_bytes�to_bytes�r&s r'�_signed_to_unsignedr`gs6���>�>�
���A�u�T��*�*�E�%����r9c��|dkr|}n)t|||dz
z�����}||z
}||z	}d|zdz
}||kr/|dz}|�|d��}d}t||z���|S)a(Return prefix length from the bitwise netmask.
    Copied from ipaddress private method

    Args:
        ip_int: An integer, the netmask in expanded bitwise format

    Returns:
        An integer, the prefix length.

    Raises:
        ValueError: If the input intermingles zeroes & ones
    rr,rXrYz&Netmask pattern %r mixes zeroes & ones)�min�
bit_lengthr^rR)	�ip_int�prefix_maxlength�trailing_zeroes�	prefixlen�leading_ones�all_ones�byteslen�details�msgs	         r'�_prefix_from_maskrmms�����{�{�*������w�&�1�*�5�A�A�C�C�
�
��!�?�2�I��_�,�L��Y��!�#�H��x���#�q�(���/�/�(�E�2�2��6����w��'�'�'��r9�
ip_addressc��|jdkr*t�|jdd�dd���St|��S)N�rXrYTrZ)�versionr\r]�packed)rns r'�pack_ip_addressrs�s@����Q����~�~�j�/����3�U�4�~�H�H�H��:���r9r
c�f�t|j��}t|j��}|||jfS�N)rs�network_address�netmaskrq)r
�net�masks   r'�pack_ip_networkrz�s4���*�4�
5�
5�C��:�-�.�.�D���j�(�(�(r9rxryrqc���|dkrJt|��dz}t|��dz}t|t��}t||f��St|t��}t||f��S)Nrp�@)r`rmrr	rr)rxryrq�prefixs    r'�unpack_ip_networkr~�sq���!�|�|�!�#�&�&�"�,��"�4�(�(�B�.��"�4��4�4���C��=�)�)�)�"�4��4�4���C��=�)�)�)r9c�D�	t|��S#t$rYdSwxYwru)r
rRr_s r'�is_netr��s5����"�~�~��������t�t����s��
�ru)1�logging�rer2�	functoolsr�	ipaddressrrrrrr	r
�typingrrr
rr.�defence360agent.utilsr�im360.utils.validaterr�	getLogger�__name__rS�compile�MrrDrE�ALL�IN�OUT�	IPNetworkrr(r8rJrVr\r`rmrsrzr~�strr��r9r'�<module>r�s�������	�	�	�	�
�
�
�
�������������������������4�3�3�3�3�3�3�3�3�3�3�3�
�
�
�
�=�=�=�=�=�=�.�.�.�.�.�.�.�.�	��	�8�	$�	$���"�*�6���=�=��#�
��S�#�
���C��+�{�*�+�	�%��
�
�8�I�+>�
�
�
�
� 	H�H�U�;��+C�%D�E�	H�	H�	H�	H����(��1���������*�C��������>��k�;�&>� ?�����)��k�;�.�/�)�
�3��S�=��)�)�)�)�*�3�*�c�*�C�*�I�*�*�*�*��s��u�T�;��;�<������r9

Zerion Mini Shell 1.0