%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /snap/core20/2379/lib/python3/dist-packages/probert/__pycache__/
Upload File :
Create Path :
Current File : //snap/core20/2379/lib/python3/dist-packages/probert/__pycache__/network.cpython-38.pyc

U

T{)_Tk�@s�ddlZddlmZddlZddlZddlZddlZddlZddlZddl	Z	ddl
mZe�d�Z
zddlmZmZWn.ek
r�Zze
�de�W5dZ[XYnXdZdZd	Zd
ZdZdZd
ZdZdZdZdZdZdZ dZ!dZ"dZ#dddddddgZ$dddd d!gZ%d"d#gZ&d$d%d&d'd(d)d*d+d,d-gd.d&d'd,d/id,d/id,d0id,d/id,d/id1�d2�d3�d,d/id&d'd,d4id,d4id5d,d/id,d6igid.d,d/id3�d5d/e$d7�d,d6igid5d/e%d7�d,d6igid5d/e&d7�d,d6igid8�d2�d&d9d&d5d,d/id,d6igid:�id5d,d/id,d6igid;�d&d,d0id,d0id,d0id,d0id,d/id<�d=�d&d'd,d4id,d4id.d,d/id3�d&d,d/id:�d>�d2�d&d'd,d6d/gid.d,d/id3�d,d6d/gid?�d2�d@�dA�Z'dBdC�Z(dDdE�Z)dFdG�Z*dHdI�Z+dJdK�Z,GdLdM�dM�Z-dNdOd%dPdQdR�Z.GdSdT�dT�Z/GdUdV�dVej0�Z1GdWdX�dXej0�Z2GdYdZ�dZe2�Z3d[d\�Z4d]d^�Z5ej6d_d`��Z7Gdadb�dbe1�Z8Gdcdd�dd�Z9Gdedf�df�Z:e;dgk�r�ddl<Z<ddl=Z=e8�Z>e>�?�Z@e<�<e>jA�e=�B�ZCe@D]ZDeC�EeDe=jF��q�eC�G�ZHeHD]\ZDZe>�IeD��q�e<�<e>jA��q�dS)h�N)�OrderedDict)�udev_get_attributeszprobert.network)�_nl80211�
_rtnetlinkz)Failed import network library modules: %s������ �@���iiii i@z
balance-rrz
active-backupzbalance-xorZ	broadcastz802.3adzbalance-tlbzbalance-albZlayer2zlayer2+3zlayer3+4zencap2+3zencap3+4ZslowZfastz'http://json-schema.org/draft-04/schema#�link�objectF�	addresses�bond�bridge�netlink_data�type�	udev_dataZarray�stringZinteger)�address�ip�family�source�scope)r�additionalProperties�
properties)r�itemsZbooleanZoneOfZnull)r�enum�Z	is_masterZis_slave�masterZslaves�mode�xmit_hash_policy�	lacp_rate�attrs)rr)rrr)�ifindex�flags�arptyper�name)rr�Z	is_bridgeZis_portZ
interfaces�options)�ssid�
visible_ssids�
scan_state)rrrrrr�wlan)z$schema�titlerrZrequiredrcCs.|sdStj�d|�}tj�|�s6t�d�|��dSd}|dkr�d}tj�tj�|d��srtj�tj�|d��rxd}nxtj�tj�|d	��r�d	}n\tj�tj�|d
��r�d}n@tj�	tj�|d��r�d
}n$tj�tj�d|��r�|�
d�r�d}n�|dk�rd}n�|dk�rNtj�tj�|d
���r*d}n"tj�tj�|d���rHd}nd}n�|dk�r^d}n~|dk�rnd}nn|dk�r~d}n^|dk�r�d}nN|dk�r�d}n>|dk�r�d }n.|d!k�r�d"}n|d#k�r�d$}n|d%k�r�d&}|�
d'��s�|�
d(��r�d(}n|�
d)��r
d)}t|�d*k�r*td+�|��dS|S),Nz???�/sys/class/netzNo sysfs path to {}rZethZwirelessZphy80211r1rZbondingrZ	tun_flagsZtapz/sys/devices/virtual/netZdummy�rZcreate_childZibZibchildrZpppiZipipiZip6tnli�loiZsiti
ZgreiZirdai!Zwlan_auxi��ZtunZipppZisdnZmip6mnharz)Failed to determine interface type for {})
�os�path�join�exists�log�debug�format�isdir�islink�isfile�
startswith�len�print)Zifacer*Z
sysfs_pathZDEV_TYPE�rC�1/usr/lib/python3/dist-packages/probert/network.py�
_compute_type�st��











rEcsj�fdd���fdd����fdd�}��fdd�}��fd	d
�}����|�|�|d�|d�|d
�d�S)Ncst�t@�dkS�Nr)�bool�
IFF_MASTERrC�r)rCrD�_iface_is_mastersz&_get_bonding.<locals>._iface_is_mastercst�t@�dkSrF)rG�	IFF_SLAVErCrIrCrD�_iface_is_slavesz%_get_bonding.<locals>._iface_is_slavecsHz*��r"td����}|��WSgWSWntk
rBgYSXdS)Nz /sys/class/net/%s/bonding/slaves��open�read�split�IOError)r�rJ�ifnamerCrD�_get_slave_iface_lists

z+_get_bonding.<locals>._get_slave_iface_listcsHz,��r$t�d��}tj�|�WSWdSWntk
rBYdSXdS)Nz/sys/class/net/%s/master)r6�readlinkr7�basenamerQ)r#)rLrSrCrD�_get_bond_masters
z&_get_bonding.<locals>._get_bond_masterc	sdzH��rFd�|f}t|��}|����}W5QRX|r@|dndWSWntk
r^YdSXdS)Nz/sys/class/net/%s/bonding/%srrM)ZparamZ
bond_paramZbprRrCrD�_get_bond_param(s
z%_get_bonding.<locals>._get_bond_paramr$r%r&r"rC)rSr)rTrWrXrC)rJrLr)rSrD�_get_bondings

�rYcsL�fdd���fdd����fdd�}���fdd�}����|�|�d	�S)
Ncstj�d�d�}tj�|�S)Nr3r�r6r7r8r9��bridge_path�rSrCrD�_iface_is_bridge?sz'_get_bridging.<locals>._iface_is_bridgecstj�d�d�}tj�|�S)Nr3�brportrZ)Zbridge_portr]rCrD�_iface_is_bridge_portCsz,_get_bridging.<locals>._iface_is_bridge_portcs$��r tj�d�d�}t�|�SgS)Nr3Zbrif)r6r7r8�listdirr[)r^rSrCrD�_get_bridge_iface_listGs
z-_get_bridging.<locals>._get_bridge_iface_listc
s�tddg�}��r$tj�d�d�}n��r<tj�d�d�}niSi}t�|�D]@}||kr\qNtj�||�}t|��}|����||<W5QRXqN|S)N�flushrr3r_)�setr6r7r8rarNrO�strip)Z
skip_attrsr\r-Zbridge_attr_nameZbridge_attr_fileZbridge_attr�r^r`rSrCrD�_get_bridge_optionsMs
z*_get_bridging.<locals>._get_bridge_optionsr,rC)rSrbrgrCrfrD�
_get_bridging=s�rhcs�fdd�}t|�S)Ncs
|j�S�N)r)�obj��attrrCrD�getjsznetlink_attr.<locals>.get��property)rlrmrCrkrD�netlink_attrisrpcs��fdd�}t|�S)Ncs&�D]}||jkr|j|Sq�Sri�r)rj�k��keys�missingrCrDrmps
zudev_attr.<locals>.getrn)rtrurmrCrsrD�	udev_attrosrvc@s�eZdZedd��Zedd��Zd#dd�Zdd	�Zd
d�Ze	d�Z
e	d
�Ze	d�Ze
dd��Zedddgd�Zedddgd�Zeddgd�Zedgd�Ze
dd��Ze
dd��Ze
d d��Ze
d!d"��ZdS)$�Linkc	CsLt�|d�}|drd}nt||d�}|i|||t||d�t|�d�S)Nr(Zis_vlanZvlanr*r))rrrrrr)�socketZif_indextonamerErYrh)�clsrrr+�typrCrCrD�from_probe_datazs�zLink.from_probe_datacCs<i}|dD]}t�|�}||t|j�<q||d<|f|�S)Nr)�Address�from_saved_data�strr)ry�	link_dataZaddress_objsZaddr�arCrCrDr}�s
zLink.from_saved_dataNcCs.||_||_||_||_||_||_||_dSri)rrrrrrr1)�selfrrrrrrr1rCrCrD�__init__�sz
Link.__init__cCs|jdkrgddd�|_dS)N)r/r.r0�r1�r�rCrCrD�mark_as_wlan�s

�zLink.mark_as_wlancCsPdd�|j��D�|j|j|j|j|jd�}|jdk	r@|j|d<t�	|t
�|S)NcSsg|]}|���qSrC)�	serialize)�.0r�rCrCrD�
<listcomp>�sz"Link.serialize.<locals>.<listcomp>)rrrrrrr1)r�valuesrrrrrr1�
jsonschema�validate�link_schema)r��rrCrCrDr��s�

zLink.serializer)r(r+cCs|jddS�Nr'rrqr�rCrCrD�<lambda>��z
Link.<lambda>ZID_VENDOR_FROM_DATABASEZ	ID_VENDORZID_VENDOR_IDzUnknown VendorZID_MODEL_FROM_DATABASEZID_MODELZID_MODEL_IDz
Unknown ModelZ
ID_NET_DRIVERZ
ID_USB_DRIVERzUnknown DriverZDEVPATHzUnknown devpathcCs|jddSr�rqr�rCrCrDr��r�cCs|jt@p|jt@Sri)r)�IFF_UP�IFF_RUNNINGr�rCrCrDr��scCs|j�d�S)Nz/devices/virtual/)�devpathr@r�rCrCrDr��r�cCs|jr|jdSdSdS)Nr.r�r�rCrCrDr.�s
z	Link.ssid)N)�__name__�
__module__�__qualname__�classmethodr{r}r�r�r�rpr)r(r+roZhwaddrrvZvendorZmodelZdriverr�Zis_connectedZ
is_virtualr.rCrCrCrDrwxs:

	�

��
�
�
�rw�globalZsiteZhostZnowhere)r�����c@s4eZdZdd�Zdd�Zedd��Zedd��Zd	S)
r|cCs,t�|�|_|jj|_||_||_||_dSri)�	ipaddressZip_interfacerrrrr)r�rrrrrCrCrDr��s

zAddress.__init__cCs|j|jt|j�|jd�S)N)rrrr)rrr~rrr�rCrCrDr��s
�zAddress.serializecCsV|d�d�}|d}|�dd�t@r,d}nd}|d}tt�||��}|||||�S)	N�local�latin-1rr)rZstaticZdhcpr)�decoderm�IFA_F_PERMANENTr~�
_scope_str)ryrrrrrrCrCrDr{�szAddress.from_probe_datacCs
tf|�Sri)r|)ryrrCrCrDr}�szAddress.from_saved_dataN)r�r�r�r�r�r�r{r}rCrCrCrDr|�s
r|c@s,eZdZdZejdd��Zejdd��ZdS)�NetworkObserverzzA NetworkObserver observes the network state.

    It calls methods on a NetworkEventReceiver in response to changes.
    cCsdSrirCr�rCrCrD�startszNetworkObserver.startcCsdSrirC�r��fdrCrCrD�
data_ready
szNetworkObserver.data_readyN)r�r�r��__doc__�abc�abstractmethodr�r�rCrCrCrDr�s

r�c@sHeZdZdZejdd��Zejdd��Zejdd��Zejdd	��Z	d
S)�NetworkEventReceiverzTNetworkEventReceiver has methods called on it in response to network
       changes.cCsdSrirC�r�r(rrCrCrD�new_linkszNetworkEventReceiver.new_linkcCsdSrirC�r�r(rCrCrD�update_linksz NetworkEventReceiver.update_linkcCsdSrirCr�rCrCrD�del_linkszNetworkEventReceiver.del_linkcCsdSrirC�r��action�datarCrCrD�route_changesz!NetworkEventReceiver.route_changeN)
r�r�r�r�r�r�r�r�r�r�rCrCrCrDr�s


r�c@s,eZdZdd�Zdd�Zdd�Zdd�Zd	S)
�TrivialEventReceivercCsdSrirCr�rCrCrDr�&szTrivialEventReceiver.new_linkcCsdSrirCr�rCrCrDr�)sz TrivialEventReceiver.update_linkcCsdSrirCr�rCrCrDr�,szTrivialEventReceiver.del_linkcCsdSrirCr�rCrCrDr�/sz!TrivialEventReceiver.route_changeN)r�r�r�r�r�r�r�rCrCrCrDr�$sr�cs�fdd�}|S)Ncs��fdd�}|S)Ncs�t�d�j||��jf}�D]}|||f7}q||jkr�|j|\}}}|dkrf�||f|j|<q�|dkr��||f|j|<q�|dkr�|dkr�|j|=q��||f|j|<n�||f|j|<dS)Nzevent for %s: %s %s�NEW�CHANGE�DEL)r:r;r��_calls)r�r�r��keyrrZ	prev_methZprev_actionZ	prev_data)�funcrtrCrD�wGs

z&coalesce.<locals>.decorator.<locals>.wrC�r�r��rt�r�rD�	decoratorFszcoalesce.<locals>.decoratorrC)rtr�rCr�rD�coalesceCsr�cs�fdd�}|S)Ncs�||f|jt�<dSri)r�rr�r�rCrDr�isznocoalesce.<locals>.wrCr�rCr�rD�
nocoalescehsr�ccsBt�|_z
dVW5|j��D]\}}}||||�qd|_XdSri)rr�r�)rj�methr�r�rCrCrD�CoalescedCallsns
r�c@sheZdZdZddd�Zdd�Zdd�Zed	�d
d��Zed	d�d
d��Z	e
dd��Zdd�Zdd�Z
dS)�UdevObserverz,Use udev/netlink to observe network changes.NcCs<i|_t��|_|dkrt�}t|t�s,t�||_d|_	dSri)
�_links�pyudevZContext�contextr��
isinstancer��AssertionError�receiverr�)r�r�rCrCrDr�|s
zUdevObserver.__init__c	Cs�t�|�|_t|��|j��W5QRX|j��|jji|_z4t�|�|_	|j	��|j�
|j	��|j	ji�Wntk
r�t�
d�YnXt|j�S)Nzcould not start wlan_listener)rZlistener�
rtlistenerr�r��filenor��_fdmapr�
wlan_listener�update�RuntimeErrorr:r;�listr�rCrCrDr��s 
�
�
zUdevObserver.startc	Cs$t|��|j|�W5QRXdSri)r�r�r�rCrCrDr��s
zUdevObserver.data_readyr(cCs�t�d||�|��D]"\}}t|t�r|�dd�||<q|d}|dkrl||jkrh|j|=|j�|�dS|dk�r||jk�r
|j|}|j	dkr�|j
t@s�|dt@r�z|�|�Wnt
k
r�t�d	�YnX||_|j	dkr�t|j�|_	t|j|jd�|_|j�|�dSt|jjt|�d
��}t|�dk�rBdS|d}t|�}	t|�|	d<t�||	�}
|
|j|<|j�||
�dS)
Nzlink_change %s %s�utf-8�replacer(r�r�r1r)zon-up trigger_scan failed)ZIFINDEXrr')r:r;r r��bytesr�r�r�r�rr)r��trigger_scanr��	exceptionrrEr+rYrr�r�r�Zlist_devicesr~rA�dictrrwr{r�)r�r�r�rr�vr(ZdevZudev_devicesZudev_devicerrrCrCrD�link_change�sD






zUdevObserver.link_changer�cCs�t�d||�|j�|d�}|dkr*dS|d�d�}|dkrb|j�|d�|j�|d�dSt	�
|�|j|<|j�|d�dS)Nzaddr_change %s %sr(r�r�r�)r:r;r�rmr�r�popr�r�r|r{)r�r�r�rrrCrCrD�addr_change�szUdevObserver.addr_changecCsLt�d||�|��D]"\}}t|t�r|�dd�||<q|j�||�dS)Nzroute_change %s %sr�r�)r:r;r r�r�r�r�r�)r�r�r�rrr�rCrCrDr��s

zUdevObserver.route_changecCs|j�|�dSri)r�r�r�rCrCrDr��szUdevObserver.trigger_scancCs�t�d|�|d}|dks&||jkr*dS|j|}|��|ddkrRd|jd<|ddkr�d	|kr�t�}|d	D]0\}}|�d
d�}|�|�|dkrt||jd
<qtt|�|jd<d|jd<|ddk�r>|j	t
@�r
z|�|�Wn tk
�rt�
d�YnXn4z|j�|t
�Wn tk
�r<t�
d�YnX|ddk�sZ|ddk�r�t|�d	g��dk�r�|d	dd�d
d�|jd
<|ddk�r�d|jd
<dS)Nz
wlan_event %sr(r�cmdZTRIGGER_SCANZscanningr0ZNEW_SCAN_RESULTS�ssidsr�r�z	no statusr.r/Z
NEW_INTERFACEzinitial trigger_scan failedzset_link_flags failedZ	ASSOCIATEZ
DISCONNECT)r:r;r�r�r1rdr��add�sortedr)r�r�r�r�r�Zset_link_flagsrArm)r��argr(rr�r.ZstatusrCrCrD�
wlan_event�sB



�zUdevObserver.wlan_event)N)r�r�r�r�r�r�r�r�r�r�r�r�r�r�rCrCrCrDr�ys
	
,


r�c@s0eZdZdZdd�Zdd�Zdd�Zdd	�Zd
S)�StoredDataObserverzVA cheaty observer that just pretends the network is in some
       pre-arranged state.cCs,||_|jdD]}t�|t�q||_dS)N�links)�
saved_datar�r�r�r�)r�r�r�r�rCrCrDr�
szStoredDataObserver.__init__cCsL|jdD]}t�|�}|j�|j|�q
|jdD]}|j�d|�q4gS)Nr��routesr�)r�rwr}r�r�r(r�)r�r�rrCrCrDr�s
zStoredDataObserver.startcCsdSrirCr�rCrCrDr�szStoredDataObserver.trigger_scancCsdSrirCr�rCrCrDr�szStoredDataObserver.data_readyN)r�r�r�r�r�r�r�r�rCrCrCrDr�	s
r�c@seZdZdd�ZdS)�
NetworkProbercCslGdd�dt�}|�}t|�}|��ggd�}|jD]}|d�|���q6|jD]}|d�|�qT|S)Nc@s$eZdZdd�Zdd�Zdd�ZdS)z/NetworkProber.probe.<locals>.CollectingReceivercSst�|_g|_dSri)rd�	all_links�
route_datar�rCrCrDr�&sz8NetworkProber.probe.<locals>.CollectingReceiver.__init__cSs|j�|�dSri)r�r�r�rCrCrDr�*sz8NetworkProber.probe.<locals>.CollectingReceiver.new_linkcSs|j�|�dSri)r��appendr�rCrCrDr�-sz<NetworkProber.probe.<locals>.CollectingReceiver.route_changeN)r�r�r�r�r�r�rCrCrCrD�CollectingReceiver%sr�)r�r�r�r�)r�r�r�r�r�r�r�)r�r�Z	collectorZobserverZresultsrr�rCrCrD�probe$s
�

zNetworkProber.probeN)r�r�r�r�rCrCrCrDr�"sr��__main__)Jr��collectionsr�
contextlibr�r�Zloggingr6rxr�Z
probert.utilsrZ	getLoggerr:Zprobertrr�ImportError�eZwarningr�Z
IFF_BROADCASTZ	IFF_DEBUGZIFF_LOOPBACKZIFF_POINTOPOINTZIFF_NOTRAILERSr�Z	IFF_NOARPZIFF_PROMISCZIFF_ALLMULTIrHrKZ
IFF_MULTICASTZIFF_PORTSELZ
IFF_AUTOMEDIAr�Z
BOND_MODESZXMIT_HASH_POLICIESZ
LACP_RATESr�rErYrhrprvrwr�r|�ABCr�r�r�r�r��contextmanagerr�r�r�r�r�ZpprintZselect�cr�Zfdsr�ZepollZpoll_obr��registerZEPOLLINZpollZeventsr�rCrCrCrD�<module>sf
��	�	
����������������%������������
�
����yB1,	^�	"%




Zerion Mini Shell 1.0