HEX
Server: Apache
System: Linux server2.voipitup.com.au 4.18.0-553.109.1.lve.el8.x86_64 #1 SMP Thu Mar 5 20:23:46 UTC 2026 x86_64
User: posscale (1027)
PHP: 8.2.30
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //opt/saltstack/salt/lib/python3.10/site-packages/salt/modules/__pycache__/win_ip.cpython-310.pyc
o

�N�g+-�@s�dZddlZddlZddlZddlZddlZddlmZm	Z	e�
e�ZdZ
dd�Zdd�Zd	d
�Zdd�Zd
d�Zdd�Zdd�Zdd�Zdd�Zdd�Zd&dd�Zdd�Zdd�Zd d!�Zd"d#�Zd$d%�ZdS)'z1
The networking module for Windows based systems
�N)�CommandExecutionError�SaltInvocationError�ipcCstjj��rtSdS)z0
    Confine this module to Windows systems
    )Fz3Module win_ip: module only works on Windows systems)�salt�utils�platformZ
is_windows�__virtualname__�r	r	�G/opt/saltstack/salt/lib/python3.10/site-packages/salt/modules/win_ip.py�__virtual__srcCs\gd�}td|dd���}i}d}d}|D]�}|��}|s#d}d}qd|vr9|�d��dd�\}}i}|||<qd	|vrL|rE|�|�nt�d
|�q|�d	d�\}}	|��}|	��}	|��}
d|
vshd|
vrtg}|||<|�|	�qd
|
vr�|�	dg��||	i�qd|
vr�|	�dd�\}}}|dd}
|��|
d<|�
��d�|
d<q|	||<q|S)z&
    Return all interface configs
    ��netsh�	interfacer�showZconfig�cmd.runF�Zpython_shellNzConfiguration for interface�"��:zCannot parse "%s"zdns serverszwins serversz
ip address�ip_addrsz
subnet prefix� ����ZSubnet�)�Netmask)�__salt__�
splitlines�strip�rstrip�split�append�log�warning�lower�
setdefault�lstrip)�cmd�lines�retZ
current_ifaceZcurrent_ip_list�line�_�iface�key�valZlkeyZsubnet�netmaskZlast_ipr	r	r
�_interface_configssL
r/cCsgd�}td|dd�S)z�
    Return raw configs for all interfaces

    CLI Example:

    .. code-block:: bash

        salt -G 'os_family:Windows' ip.raw_interface_configs
    rrFr�r)r&r	r	r
�raw_interface_configsUs
r1cCst�S)z�
    Return configs for all interfaces

    CLI Example:

    .. code-block:: bash

        salt -G 'os_family:Windows' ip.get_all_interfaces
    )r/r	r	r	r
�get_all_interfacescs
r2cCst��|i�S)z�
    Return the configuration of a network interface

    CLI Example:

    .. code-block:: bash

        salt -G 'os_family:Windows' ip.get_interface 'Local Area Connection'
    )r/�get�r+r	r	r
�
get_interfaceps
r5cCsjddddd|��g}d}td|dd���D]}d|vr(d	}|��d
dkSq|s3td|�d
���dS)z�
    Returns ``True`` if interface is enabled, otherwise ``False``

    CLI Example:

    .. code-block:: bash

        salt -G 'os_family:Windows' ip.is_enabled 'Local Area Connection #2'
    r
rr�name=FrrzConnect state:TrZ	ConnectedzInterface 'z' not found)rrrr)r+r&Ziface_foundr)r	r	r
�
is_enabled}s
�r7cCs
t|�S)z�
    Returns ``True`` if interface is disabled, otherwise ``False``

    CLI Example:

    .. code-block:: bash

        salt -G 'os_family:Windows' ip.is_disabled 'Local Area Connection #2'
    )r7r4r	r	r
�is_disabled�s

r8cC�:t|�rdSddddd|��dg}td|dd	�t|�S)
z�
    Enable an interface

    CLI Example:

    .. code-block:: bash

        salt -G 'os_family:Windows' ip.enable 'Local Area Connection #2'
    Tr
r�setr6z
admin=ENABLEDrFr)r7r�r+r&r	r	r
�enable��
�r<cCr9)
z�
    Disable an interface

    CLI Example:

    .. code-block:: bash

        salt -G 'os_family:Windows' ip.disable 'Local Area Connection #2'
    Tr
rr:r6zadmin=DISABLEDrFr)r8rr;r	r	r
�disable�r=r>cCs.tjjj�|�std|�d���tjj�|�S)z�
    Convenience function to convert the netmask to the CIDR subnet length

    CLI Example:

    .. code-block:: bash

        salt -G 'os_family:Windows' ip.get_subnet_length 255.255.255.0
    �'z' is not a valid netmask)rr�validate�netr.r�networkZget_net_size)�maskr	r	r
�get_subnet_length�s
rDFc	CsFddd�}tjjj�|�std|�d���|r'tjjj�|�s'td|�d���d|vr/|d7}|rA|||�rAtd	|�d
|�d���gd�}|rM|�d�n|�d
�|�dd|��g�|sc|�d�|�d|���|ru|�d|���t	d|dd�}|ddkr�td�
|d���|||dd�}|s�iSd|i}|r�||d<|S) a�
    Set static IP configuration on a Windows NIC

    iface
        The name of the interface to manage

    addr
        IP address with subnet length (ex. ``10.1.2.3/24``). The
        :mod:`ip.get_subnet_length <salt.modules.win_ip.get_subnet_length>`
        function can be used to calculate the subnet length from a netmask.

    gateway : None
        If specified, the default gateway will be set to this value.

    append : False
        If ``True``, this IP address will be added to the interface. Default is
        ``False``, which overrides any existing configuration for the interface
        and sets ``addr`` as the only address on the interface.

    CLI Example:

    .. code-block:: bash

        salt -G 'os_family:Windows' ip.set_static_ip 'Local Area Connection' 10.1.2.3/24 gateway=10.1.2.1
        salt -G 'os_family:Windows' ip.set_static_ip 'Local Area Connection' 10.1.2.4/24 append=True
    rcSst|�dd�\}}tjj�|�}t|�D]$}t|��dg�D]}|d|kr1|d|kr1|Sqt�	d�qiS)N�/rrz
IP Addressr)
�rsplitrrrBZcidr_to_ipv4_netmask�ranger5r3�time�sleep)r+�addr�timeoutrZcidrr.�idxZaddrinfor	r	r
�
_find_addr�s�z!set_static_ip.<locals>._find_addrzInvalid address 'r?zInvalid default gateway 'rEz/32z	Address 'z' already exists on interface ')r
rr�addr:�addressr6�
source=static�address=zgateway=zcmd.run_allFr�retcoderzUnable to set IP address: {}�stderr�
)rKzAddress InfozDefault GatewayN)r)rrr@rAZ	ipv4_addrrrr �extendr�format)	r+rJZgatewayr rMr&�result�new_addrr(r	r	r
�
set_static_ip�sB

�

�rYcC�,ddddd|dg}td|dd	�|d
d�S)z�
    Set Windows NIC to get IP from DHCP

    CLI Example:

    .. code-block:: bash

        salt -G 'os_family:Windows' ip.set_dhcp_ip 'Local Area Connection'
    r
rrr:rO�dhcprFr�Yes)�	Interface�DHCP enabledr0r;r	r	r
�set_dhcp_ip.�

r_c
Gs|rt|d���dkr|dd�St|d���dkr:t�d�ddd	d
dd|��d
dg}td|dd�|gd�Sd}|D]C}|dkrbddd	d
dd|��d
d|��dg	}td|dd�|d}q>ddd	ddd|��d|��d|��g}td|dd�|d}q>||d�S)a�
    Set static DNS configuration on a Windows NIC

    Args:

        iface (str): The name of the interface to set

        addrs (*):
            One or more DNS servers to be added. To clear the list of DNS
            servers pass an empty list (``[]``). If undefined or ``None`` no
            changes will be made.

    Returns:
        dict: A dictionary containing the new DNS settings

    CLI Example:

    .. code-block:: bash

        salt -G 'os_family:Windows' ip.set_static_dns 'Local Area Connection' '192.168.1.1'
        salt -G 'os_family:Windows' ip.set_static_dns 'Local Area Connection' '192.168.1.252' '192.168.1.253'
    rZnonez
No Changes�r]�
DNS Serverz[]zClearing list of DNS serversr
rrr:�dnsr6rPzaddress=nonerFrrrQzregister=primaryrNzindex=)�strr#r!�debugr)r+�addrsr&Z
addr_indexrJr	r	r
�set_static_dns=sT

�

�
�


rgcCrZ)z�
    Set DNS source to DHCP on Windows

    CLI Example:

    .. code-block:: bash

        salt -G 'os_family:Windows' ip.set_dhcp_dns 'Local Area Connection'
    r
rrr:rcr[rFr�DHCPrar0r;r	r	r
�set_dhcp_dns�r`ricCst|�t|�|ddd�S)z�
    Set both IP Address and DNS to DHCP

    CLI Example:

    .. code-block:: bash

        salt -G 'os_family:Windows' ip.set_dhcp_all 'Local Area Connection'
    rhr\)r]rbr^)r_rir4r	r	r
�set_dhcp_all�s
rjcCsDzttdd�tdgd�dd���D���WSty!td��w)z�
    Set DNS source to DHCP on Windows

    CLI Example:

    .. code-block:: bash

        salt -G 'os_family:Windows' ip.get_default_gateway
    css$�|]
}d|vr|��dVqdS)zDefault Gateway:rN)r)�.0�xr	r	r
�	<genexpr>�s�
��z&get_default_gateway.<locals>.<genexpr>rrFrzUnable to find default gateway)�next�iterrr�
StopIterationrr	r	r	r
�get_default_gateway�s
���	�rq)NF)�__doc__�loggingrHZsalt.utils.networkrZsalt.utils.platformZsalt.utils.validate.netZsalt.exceptionsrr�	getLogger�__name__r!rrr/r1r2r5r7r8r<r>rDrYr_rgrirjrqr	r	r	r
�<module>s2
	8



PH