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/runners/__pycache__/net.cpython-310.pyc
o

�N�g{��@s dZddlZddlZzddlmZddlmZddl	m
Z
dZWney+dZYnwdZ
d	ZgZdZd
ZiZdZdd
�Zdd�Zdd�Zefdd�Zdd�Zdd�Zdd�Zddddddefdd�Zddddefdd�Zddddefdd�Zdddddefd d!�Zdefd"d#�Zd$d%�Z dS)&a;
NET Finder
==========

.. versionadded:: 2017.7.0

A runner to find network details easily and fast.
It's smart enough to know what you are looking for.

Configuration
-------------

- Minion (proxy) config

    To have the complete features, one needs to add the following mine configuration in the minion (proxy) config file:

    .. code-block:: yaml

        mine_functions:
          net.ipaddrs: []
          net.lldp: []
          net.mac: []
          net.arp: []
          net.interfaces: []

    Which instructs Salt to cache the data returned by the NAPALM-functions.
    While they are not mandatory, the less functions configured, the less details will be found by the runner.

    How often the mines are refreshed, can be specified using:

    .. code-block:: yaml

        mine_interval: <X minutes>

- Master config

    By default the following options can be configured on the master.
    They are not necessary, but available in case the user has different requirements.

    target: ``*``
        From what minions will collect the mine data. Default: ``*`` (collect from all minions).

    expr_form: ``glob``
        Minion matching expression form. Default: ``glob``.

    ignore_interfaces
        A list of interfaces name to ignore. By default will consider all interfaces.

    display: ``True``
        Display on the screen or return structured object? Default: ``True`` (return on the CLI).

    outputter: ``table``
        Specify the outputter name when displaying on the CLI. Default: :mod:`table <salt.output.napalm_bgp>`.

    Configuration example:

    .. code-block:: yaml

        runners:
          net.find:
            target: 'edge*'
            expr_form: 'glob'
            ignore_interfaces:
              - lo0
              - em1
              - jsrv
              - fxp0
            outputter: yaml
�N)�helpers)�	IPNetwork)�AddrFormatErrorTF�*�glob�table�netcCstrtSdS)N)Fz'The napalm module could not be imported)�
HAS_NAPALM�__virtualname__�rr�D/opt/saltstack/salt/lib/python3.10/site-packages/salt/runners/net.py�__virtual__qsr
cCsLt�di��di�}|�dt�|�dt�|�dt�|�dt�|�dt�d�S)	z-
    Return the net.find runner options.
    Zrunnersznet.find�target�	expr_form�ignore_interfaces�display�	outputter)rrrrr)�__opts__�get�_DEFAULT_TARGET�_DEFAULT_EXPR_FORM�_DEFAULT_IGNORE_INTF�_DEFAULT_DISPLAY�_DEFAULT_OUTPUTTER)Zrunner_optsrrr�_get_net_runner_optsws




�rcCsH|tvrt|rt|St�}td|�d�||�d�d�t|<t|S)z|
    Return the mine function from all the targeted minions.
    Just a small helper to avoid redundant pieces of code.
    zmine.getrr)Ztgt_type)�_CACHErZ__salt__r)Zfun�net_runner_optsrrr�	_get_mine�s
�rcCs^|r-t�}|�d�dkrtjj||d�dt|ddd�}ntj�||�d�t�}t|�dS|S)z%
    Display or return the rows.
    rr)�rows�labelsrr)�titleZrows_keyZ
labels_keyN)rr�salt�outputZ
out_formatr�print)rrr rr�retrrr�_display_runner�s �	�r%cCs*d}zt|�}W|Sty|YSw)zA
    Try to convert a string into a valid IP Network object.
    N)rr)�addrZip_netwrrr�_get_network_obj�s
��r'c
Csz	t�tj|�}WntyddgfYSwtd�}td�}|��D]a\}}|�dd�s/q$|�di���D]M\}}zt�tj|�d��}Wn	tyPYq7w||krVq7|�|i��di��|i�}|�di�}	|	�|�d	i��d
d�|	��D�}
|||
fSq$ddgfS)zD
    Helper to search the interfaces IPs using the MAC address.
    ��net.interfaces�net.ipaddrs�resultF�out�mac_address�ipv4�ipv6c	S�$g|]\}}d�||�dd���qS�z{}/{}Z
prefix_lengthZ32��formatr��.0Zip_addrZaddr_detailsrrr�
<listcomp>����z'_find_interfaces_ip.<locals>.<listcomp>)�napalm_helpers�convert�macrr�itemsr�update)r:�all_interfaces�all_ipaddrs�deviceZdevice_interfaces�	interface�interface_details�
interface_mac�interface_ipaddrs�ip_addresses�
interface_ipsrrr�_find_interfaces_ip�s<������
rFc
	Cs�td�}td�}|��D]U\}}|�dd�sq|�di���D]A\}}t|�di����}|�t|�di�����|D]#}||krCq<|�|i��di��|i��dd	�}	|||	fSqqd
S)zM
    Helper to get the interfaces hardware address using the IP Address.
    r)r*r+Fr,r.r/r-r()r(r(r()rr;r�set�keysr<)
�ipr=r>r?Zdevice_ipaddrsr@rCrDZipaddrrBrrr�_find_interfaces_mac�s(
���rJcsF�fdd��ddddddd	d
d�}g}t�}	|rd�|�}|sId
}|r+|d|��7}n|d7}|r8|d|��7}�rI|dt����7}|rI|d7}td�}
td�}|r[||
�|i�i}
�rft�t�sft���i}td�}
|
��D�]\}}|sxqp|�dd�sqp|�di�}|r�||�|i�i}|��D]�\}}|s�q��r�||	�d�vr�q�|�dd�p�d}|r�|�	�|�	�vr�q�|�|i��dd�s�q�g}||||�dd�p�d|�dd�p�d|�dd�p�dt
�t
j|�dd�p�d�gd�}d}|�|i��di���D]y\}}|�
d �d!|k�rs|�d"i�}|�|�d#i��d$d%�|��D�}i}|�|�||d&<|�r7d'�|d&�|d&<��rl�fd(d%�|D�}|�rk|�rd|
g}|�ttt|���t|�}||
k�rc|}
|}q�d)}|�|�q�d)}|�|�q�|�s���s�i}|�|�|�r�d|d&<|�|�q�qp��r�|�r�|�r�|g}t||||d*�S)+aP	
    Search for interfaces details in the following mine functions:

    - net.interfaces
    - net.ipaddrs

    Optional arguments:

    device
        Return interface data from a certain device only.

    interface
        Return data selecting by interface name.

    pattern
        Return interfaces that contain a certain pattern in their description.

    ipnet
        Return interfaces whose IP networks associated include this IP network.

    best: ``True``
        When ``ipnet`` is specified, this argument says if the runner should return only the best match
        (the output will contain at most one row). Default: ``True`` (return only the best match).

    display: True
        Display on the screen or return structured object? Default: ``True`` (return on the CLI).

    title
        Display a custom title for the table.

    CLI Example:

    .. code-block:: bash

        $ sudo salt-run net.interfaces interface=vt-0/0/10

    Output Example:

    .. code-block:: text

        Details for interface xe-0/0/0
        _________________________________________________________________________________________________________________
        |    Device    | Interface | Interface Description |  UP  | Enabled | Speed [Mbps] | MAC Address | IP Addresses |
        _________________________________________________________________________________________________________________
        | edge01.bjm01 | vt-0/0/10 |                       | True |   True  |     1000     |             |              |
        _________________________________________________________________________________________________________________
        | edge01.flw01 | vt-0/0/10 |                       | True |   True  |     1000     |             |              |
        _________________________________________________________________________________________________________________
        | edge01.pos01 | vt-0/0/10 |                       | True |   True  |     1000     |             |              |
        _________________________________________________________________________________________________________________
        | edge01.oua01 | vt-0/0/10 |                       | True |   True  |     1000     |             |              |
        _________________________________________________________________________________________________________________
    cs,|dkrdSt|�}|sdS�|vp|�vS)zX
        Helper to tell if a IP address or network belong to a certain network.
        �	0.0.0.0/0F)r')rZnet_obj)�ipnetrr�_ipnet_belongs<sz"interfaces.<locals>._ipnet_belongs�Device�	InterfacezInterface DescriptionZUPZEnabledzSpeed [Mbps]zMAC AddresszIP Addresses)r?r@�interface_description�is_up�
is_enabled�speedr:�ipszAPattern "{}" found in the description of the following interfacesZDetails� for interface � for all interfaces� on device z that include network z - only best match returnedr)r*rKr+Fr,r�descriptionr(rQrRrSr-�.rr.r/c	Sr0r1r2r4rrrr6�r7zinterfaces.<locals>.<listcomp>rT�
csg|]
}�|�rt|��qSr)�str)r5rI)rMrrr6�s
��T�r)rr3r[rr�
isinstancerr'r;�lowerr8r9r:�splitr<�join�extend�list�map�max�appendr%)r?r@r �patternrL�bestrrrrr=r>Zbest_rowZbest_net_matchZnet_interfaces_outZselected_device_interfacesZinterface_namerArPrTZdevice_entryZintf_entry_found�intrfrErDZinterf_entryZinet_ipsZcompareZnew_best_net_matchr)rMrLr�
interfaces�s�?�
������
�
��

�
�
�
�

��Eric
Cs`dddddd�}g}td�}d}|r|d	|��7}|r"|d
|��7}|r+|d|��7}|r4|d|��7}|r=||�|�i}|��D]f\}}	|	sHqA|	�d
d�sOqA|	�dg�}
|
D]O}|rg|�dd���|��ks�|rq||�dd�vs�|r�t�tj|�dd��t�tj|�kr�|�||�d�t�tj|�d��t�tj|�d��|�d�d��qWqAt	||||d�S)ai
    Search for entries in the ARP tables using the following mine functions:

    - net.arp

    Optional arguments:

    device
        Return interface data from a certain device only.

    interface
        Return data selecting by interface name.

    mac
        Search using a specific MAC Address.

    ip
        Search using a specific IP Address.

    display: ``True``
        Display on the screen or return structured object? Default: ``True``, will return on the CLI.

    CLI Example:

    .. code-block:: bash

        $ sudo salt-run net.findarp mac=8C:60:0F:78:EC:41

    Output Example:

    .. code-block:: text

        ARP Entries for MAC 8C:60:0F:78:EC:41
        ________________________________________________________________________________
        |    Device    |     Interface     |        MAC        |       IP      |  Age  |
        ________________________________________________________________________________
        | edge01.bjm01 | irb.171 [ae0.171] | 8C:60:0F:78:EC:41 | 172.172.17.19 | 956.0 |
        ________________________________________________________________________________
    rNrO�MACZIPZAge)r?r@r:rI�ageznet.arpzARP EntriesrW� on interface z for IP z	 for MAC r+Fr,r:r(r@rIrkr\)
rrr;r^r8r9rIrer:r%)r?r@r:rIrrrZall_arpr Z
device_arpZ	arp_tableZ	arp_entryrrr�findarp�sl+������������rmcCsbddddddddd	�}g}td
�}d}|r|d|��7}|r%|d
|��7}|r.|d|��7}|r7||�|�i}|��D]m\}}	|	sBq;|	�dd�sIq;|	�dg�}
|
D]V}|rgt�tj|�dd��t�tj|�ks|rq||�dd�vs|r�t|�dd��t|�kr�|�||�d�t�tj|�d��|�d�|�d�|�d�|�d�|�d�d	��qQq;t||||d�S)a�
    Search in the MAC Address tables, using the following mine functions:

    - net.mac

    Optional arguments:

    device
        Return interface data from a certain device only.

    interface
        Return data selecting by interface name.

    mac
        Search using a specific MAC Address.

    vlan
        Search using a VLAN ID.

    display: ``True``
        Display on the screen or return structured object? Default: ``True``, will return on the CLI.

    CLI Example:

    .. code-block:: bash

        $ sudo salt-run net.findmac mac=8C:60:0F:78:EC:41

    Output Example:

    .. code-block:: text

        MAC Address(es)
        _____________________________________________________________________________________________
        |    Device    | Interface |        MAC        | VLAN | Static | Active | Moves | Last move |
        _____________________________________________________________________________________________
        | edge01.bjm01 |  ae0.171  | 8C:60:0F:78:EC:41 | 171  | False  |  True  |   0   |    0.0    |
        _____________________________________________________________________________________________
    rNrOrjZVLANZStaticZActiveZMovesz	Last Move)r?r@r:�vlan�static�active�moves�	last_moveznet.maczMAC Address(es)rWrlz	 on VLAN r+Fr,r:r(r@rnrorprqrrr\)	rrr;r8r9r:r[rer%)r?r:r@rnrrrZall_macr Z
device_macZ	mac_tableZ	mac_entryrrr�findmac2sp)�
����������rscCs�td�}dddddddd	d
�}g}|rd�|�}|s<d}|r&|d
|��7}n|d7}|r3|d|��7}|r<|d|��7}|rE||�|�i}|��D]�\}}	|	sPqI|	�dd�sWqI|	�di�}
|rg||
�|g�i}
|
��D]}\}}|srqk|D]s}
|
�dd�p}d}|
�dd�p�d}|
�dd�p�d}|
�dd�p�d}|
�dd�p�d}|r�|��}||��vs�||��vs�||��vs�||��vs�qt|r�t�tj|�t�tj|�kr�qt|�|||
�dd�p�dt�tj|�||||d��qtqkqIt	||||d�S)a�
    Search in the LLDP neighbors, using the following mine functions:

    - net.lldp

    Optional arguments:

    device
        Return interface data from a certain device only.

    interface
        Return data selecting by interface name.

    pattern
        Return LLDP neighbors that have contain this pattern in one of the following fields:

        - Remote Port ID
        - Remote Port Description
        - Remote System Name
        - Remote System Description

    chassis
        Search using a specific Chassis ID.

    display: ``True``
        Display on the screen or return structured object? Default: ``True`` (return on the CLI).

    display: ``True``
        Display on the screen or return structured object? Default: ``True`` (return on the CLI).

    title
        Display a custom title for the table.

    CLI Example:

    .. code-block:: bash

        $ sudo salt-run net.lldp pattern=Ethernet1/48

    Output Example:

    .. code-block:: text

        Pattern "Ethernet1/48" found in one of the following LLDP details
        _________________________________________________________________________________________________________________________________________________________________________________________
        |    Device    | Interface | Parent Interface | Remote Chassis ID | Remote Port ID | Remote Port Description |   Remote System Name   |            Remote System Description            |
        _________________________________________________________________________________________________________________________________________________________________________________________
        | edge01.bjm01 |  xe-2/3/4 |       ae0        | 8C:60:4F:3B:52:19 |                |       Ethernet1/48      | edge05.bjm01.dummy.net |   Cisco NX-OS(tm) n6000, Software (n6000-uk9),  |
        |              |           |                  |                   |                |                         |                        | Version 7.3(0)N7(5), RELEASE SOFTWARE Copyright |
        |              |           |                  |                   |                |                         |                        |  (c) 2002-2012 by Cisco Systems, Inc. Compiled  |
        |              |           |                  |                   |                |                         |                        |                2/17/2016 22:00:00               |
        _________________________________________________________________________________________________________________________________________________________________________________________
        | edge01.flw01 |  xe-1/2/3 |       ae0        | 8C:60:4F:1A:B4:22 |                |       Ethernet1/48      | edge05.flw01.dummy.net |   Cisco NX-OS(tm) n6000, Software (n6000-uk9),  |
        |              |           |                  |                   |                |                         |                        | Version 7.3(0)N7(5), RELEASE SOFTWARE Copyright |
        |              |           |                  |                   |                |                         |                        |  (c) 2002-2012 by Cisco Systems, Inc. Compiled  |
        |              |           |                  |                   |                |                         |                        |                2/17/2016 22:00:00               |
        _________________________________________________________________________________________________________________________________________________________________________________________
        | edge01.oua01 |  xe-0/1/2 |       ae1        | 8C:60:4F:51:A4:22 |                |       Ethernet1/48      | edge05.oua01.dummy.net |   Cisco NX-OS(tm) n6000, Software (n6000-uk9),  |
        |              |           |                  |                   |                |                         |                        | Version 7.3(0)N7(5), RELEASE SOFTWARE Copyright |
        |              |           |                  |                   |                |                         |                        |  (c) 2002-2012 by Cisco Systems, Inc. Compiled  |
        |              |           |                  |                   |                |                         |                        |                2/17/2016 22:00:00               |
        _________________________________________________________________________________________________________________________________________________________________________________________
    znet.lldprNrOzParent InterfacezRemote Chassis IDzRemote Port IDzRemote Port DescriptionzRemote System NamezRemote System Description)r?r@�parent_interface�remote_chassis_id�remote_port_idZremote_port_desc�remote_system_nameZremote_system_descz7Pattern "{}" found in one of the following LLDP detailszLLDP NeighborsrUrVrWz having Chassis ID r+Fr,rwr(rvZremote_system_descriptionZremote_port_descriptionrurt)r?r@rtrurvZremote_port_descrrwZremote_system_descrr\)
rr3rr;r^r8r9r:rer%)r?r@r rf�chassisrZall_lldprrZdevice_lldpZlldp_interfacesrhZinterface_lldpZlldp_rowZrsnZrpiZrsdZrpdZrciZptlrrr�lldp�s�G�
��������)rycCs�|s
|rtd�iSd}d}d}d}d}idg�dg�dg�dg�dg�d	g�d
g�dg�dg�d
g�dg�dg�dg�dg�dg�dg�dg�}t|t�r\t||d�|d<|sZ|SdSz	t�tj|�}Wn	tynYnwtj	j
�|�rxd}|s�z	t�tj|�}Wn	t
y�Ynwt|�}|r�t|||d�|d<|s�|s�t||d�|d<t||d�|d<t||d�|d	<t||d�|d
<t||d�|d<t||d�|d<t||d�|d<t||d�|d<t||d�|d<t||d�|d<|s�|S|�rt||d�|d<t||d�|d<t||d�|d
<|�rt||d�|d<|�rBt|�\}}}	d�|	�}|�rA|�rAd j|||d!�}
t|||
|d"�|d<n"|�rdt|�\}}}|�rd|�rdd#j|||d$�}
t|||
|d"�|d<|�rs|�rst|||d%�|d<|�sx|SdS)&a�
    Search in all possible entities (Interfaces, MAC tables, ARP tables, LLDP neighbors),
    using the following mine functions:

    - net.mac
    - net.arp
    - net.lldp
    - net.ipaddrs
    - net.interfaces

    This function has the advantage that it knows where to look, but the output might
    become quite long as returns all possible matches.

    Optional arguments:

    best: ``True``
        Return only the best match with the interfaces IP networks
        when the saerching pattern is a valid IP Address or Network.

    display: ``True``
        Display on the screen or return structured object? Default: ``True`` (return on the CLI).

    CLI Example:

    .. code-block:: bash

        $ sudo salt-run net.find 10.10.10.7

    Output Example:

    .. code-block:: text

        Details for all interfaces that include network 10.10.10.7/32 - only best match returned
        ________________________________________________________________________________________________________________________
        |    Device    | Interface | Interface Description |  UP  | Enabled | Speed [Mbps] |    MAC Address    |  IP Addresses |
        ________________________________________________________________________________________________________________________
        | edge01.flw01 |    irb    |                       | True |   True  |      -1      | 5C:5E:AB:AC:52:B4 | 10.10.10.1/22 |
        ________________________________________________________________________________________________________________________

        ARP Entries for IP 10.10.10.7
        _____________________________________________________________________________
        |    Device    |     Interface     |        MAC        |     IP     |  Age  |
        _____________________________________________________________________________
        | edge01.flw01 | irb.349 [ae0.349] | 2C:60:0C:2A:4C:0A | 10.10.10.7 | 832.0 |
        _____________________________________________________________________________
    z>Please type a valid MAC/IP Address / Device / Interface / VLANr(NZint_netZ	int_descrZint_nameZint_ipZint_macZ
int_deviceZ
lldp_descrZlldp_intZlldp_deviceZlldp_macZlldp_device_intZ
mac_deviceZmac_intZ
arp_deviceZarp_intZarp_macZarp_ip)rnrr:F)rLrgr)rfr)r@r)r?r)r:r)rxr)rIrz, zBInterface {interface} on {device} has the physical address ({mac}))r@r?r:)r?r@r rz=IP Address {ip} is set for interface {interface}, on {device})r@r?rIr\)r#r]�intrsr8r9r:�
IndexErrorr!�utils�networkZis_ipv6rI�
ValueErrorr'riryrmrFr`r3rJ)r&rgrr?r@r:rIrL�resultsrTr rrr�find2s�/��������	�
���
�����
���
�
����
��r�cOsLi}t|�D]}t||�dd�|�dt�d�}|||<q|�dt�s$|SdS)a0

    Execute multiple search tasks.
    This function is based on the `find` function.
    Depending on the search items, some information might overlap.

    Optional arguments:

    best: ``True``
        Return only the best match with the interfaces IP networks
        when the saerching pattern is a valid IP Address or Network.

    display: ``True``
        Display on the screen or return structured object? Default: `True` (return on the CLI).

    CLI Example:

    .. code-block:: bash

        $ sudo salt-run net.multi_find Ethernet1/49 xe-0/1/2

    Output Example:

    .. code-block:: text

        Pattern "Ethernet1/49" found in one of the following LLDP details

            -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
            |    Device    | Interface | Parent Interface | Remote Chassis ID | Remote Port Description | Remote Port ID |          Remote System Description          |   Remote System Name   |
            -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
            | edge01.oua04 |  xe-0/1/2 |       ae1        | DE:AD:BE:EF:DE:AD |       Ethernet1/49      |                | Cisco NX-OS(tm) n6000, Software (n6000-uk9) | edge07.oua04.dummy.net |
            -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

        Details for interface xe-0/1/2

            -----------------------------------------------------------------------------------------------------------------------
            |    Device    | Interface | Interface Description | IP Addresses | Enabled |  UP  |    MAC Address    | Speed [Mbps] |
            -----------------------------------------------------------------------------------------------------------------------
            | edge01.oua04 |  xe-0/1/2 |     ae1 sw01.oua04    |              |   True  | True | BE:EF:DE:AD:BE:EF |    10000     |
            -----------------------------------------------------------------------------------------------------------------------

        LLDP Neighbors for interface xe-0/1/2

            -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
            |    Device    | Interface | Parent Interface | Remote Chassis ID | Remote Port Description | Remote Port ID |          Remote System Description          |   Remote System Name   |
            -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
            | edge01.oua04 |  xe-0/1/2 |       ae1        | DE:AD:BE:EF:DE:AD |       Ethernet1/49      |                | Cisco NX-OS(tm) n6000, Software (n6000-uk9) | edge07.oua04.dummy.net |
            -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    rgTr)rgrN)rGr�rr)�patterns�kwargsr,rfZ
search_resultrrr�
multi_find�s1

�
�r�)!�__doc__Zsalt.outputr!Zsalt.utils.networkZnapalm.baserr8ZnetaddrrZnetaddr.corerr	�ImportErrorrrrrrrr
r
rrr%r'rFrJrirmrsryr�r�rrrr�<module>s`F�&!
�
P
�gf
�