CasperSecurity

Current Path : /lib/python3/dist-packages/landscape/lib/__pycache__/
Upload File :
Current File : //lib/python3/dist-packages/landscape/lib/__pycache__/sysstats.cpython-310.pyc

o

���c��@s�ddlmZddlZddlZddlZddlZddlmZddlmZddl	m
Z
Gdd�de�ZGdd	�d	e
�Zd
d�Zdd
d�Zddd�ZGdd�de
�ZGdd�de
�ZGdd�de
�ZGdd�de
�ZdS)�)�datetimeN)�getProcessOutputAndValue)�
encode_values)�to_timestampc@seZdZdZdS)�CommandErrorz:Raised when an external command returns a non-zero status.N)�__name__�
__module__�__qualname__�__doc__�rr�8/usr/lib/python3/dist-packages/landscape/lib/sysstats.pyr
src@s^eZdZddd�Zedd��Zedd��Zedd	��Zed
d��Zedd
��Z	edd��Z
dS)�MemoryStats�
/proc/meminfocCs�i}t|�D]}d|vr"|�dd�\}}|dvr"t|��d�||<q|dd|_|d|d|d	d|_|d
d|_|dd|_dS)N�:�)�MemTotal�SwapFree�	SwapTotal�MemFree�Buffers�Cachedrrirrrrr)�open�split�int�total_memory�free_memory�
total_swap�	free_swap)�self�filename�data�line�key�valuerrr�__init__s���zMemoryStats.__init__cC�|j|jS�N)rr�rrrr�used_memory"�zMemoryStats.used_memorycCr%r&)rrr'rrr�	used_swap&r)zMemoryStats.used_swapcCs|jt|j�dS�N�d)r�floatrr'rrr�free_memory_percentage*sz"MemoryStats.free_memory_percentagecCs"|jdkrdS|jt|j�dS�Nrgr,)rrr-r'rrr�free_swap_percentage.s
z MemoryStats.free_swap_percentagecCs
d|jSr+)r.r'rrr�used_memory_percentage5s
z"MemoryStats.used_memory_percentagecCs|jdkrdSd|jSr/)rr0r'rrr�used_swap_percentage9s

z MemoryStats.used_swap_percentageN)r)rrr	r$�propertyr(r*r.r0r1r2rrrrr
s





r
cCs,ttj�}tddg|d�}dd�}|�|�S)N�whoz-q)�envcSsJ|\}}}|dkrt|�d���|�dd�d}|�d�}tt|����S)Nr�ascii�
r)r�decoder�sorted�set)�args�stdout_data�stderr_data�status�
first_linerrr�parse_outputEs

z)get_logged_in_users.<locals>.parse_output)r�os�environr�addCallback)rB�resultr@rrr�get_logged_in_usersAs

rE�/proc/uptimecCsFt|d��}|��}Wd�n1swY|��\}}t|�S)z�
    This parses a file in /proc/uptime format and returns a floating point
    version of the first value (the actual uptime).
    �rN)r�readlinerr-)�uptime_file�ufiler �up�idlerrr�
get_uptimeOs

�rMccsT�|durtj�d�rd}nd}tj�|�r&tt�|��D]
}t||�VqdSdS)Nz/sys/class/thermalz/proc/acpi/thermal_zone)rA�path�isdirr9�listdir�ThermalZone)�thermal_zone_path�	zone_namerrr�get_thermal_zonesZs��rTc@s eZdZdZdZdZdd�ZdS)rQNc	CsJ||_tj�||�|_tj�|jd�}tj�|�rcz?t|��-}|��}zt|���d|_	d|_
d�|j	|j
�|_Wn	t
yCYnwWd�n1sNwYWdSWdStybYdSwtj�|jd�}tj�|�r�t|�D]-}|�d�r�|dd���|_z|j��\}}t|�|_	||_
Wqut
y�YquwqudSdS)N�tempg@�@�Cz	{:.1f} {}�temperatureztemperature:�)�namerArN�join�isfilerrHr�strip�temperature_value�temperature_unit�formatrW�
ValueError�EnvironmentError�
startswithr)r�	base_pathrY�temperature_path�fr!r#�unitrrrr$ksH

���(�	�


���zThermalZone.__init__)rrr	rWr]r^r$rrrrrQes
rQc@s$eZdZdZdZdd�Zdd�ZdS)�	LoginInfoz=Information about a login session gathered from wtmp or utmp.�hi32s4s32s256shhiiiiiii20scCs�t�|j|�}|d|_|d|_|�|d�|_|�|d�|_|�|d�|_|�|d�|_	|d|_
|d|_|d	|_t
�|d
�|_|d|_dS)Nrr��������	�)�struct�unpack�
RAW_FORMAT�
login_type�pid�_strip_and_decode�
tty_device�id�username�hostname�termination_status�exit_status�
session_idr�utcfromtimestamp�
entry_time�remote_ip_address)r�raw_data�inforrrr$�s




zLoginInfo.__init__cCs|�d��d�S)z>Helper method to strip b"" and return a utf-8 decoded string.�zutf-8)r\r8)r�
bytestringrrrrw�szLoginInfo._strip_and_decodeN)rrr	r
rtr$rwrrrrrg�s
rgc@s(eZdZdZdd�Zdd�Zdd�ZdS)	�LoginInfoReaderzwReader parses C{/var/log/wtmp} and/or C{/var/run/utmp} files.

    @file: Initialize the reader with an open file.
    cCs||_t�tj�|_dSr&)�_filerr�calcsizergrt�_struct_length)r�filerrrr$�szLoginInfoReader.__init__ccs�	|��}|s
dS|Vq)z2Returns a generator that yields LoginInfo objects.TN)�	read_next)rr�rrr�
login_info�s��zLoginInfoReader.login_infocCs,|j�|j�}|rt|�|jkrt|�SdS)z9Returns login data or None if no login data is available.N)r��readr��lenrg)rr rrrr��szLoginInfoReader.read_nextN)rrr	r
r$r�r�rrrrr��s

r�c@s2eZdZdZdZ		d
dd�Zdd�Zdd	�ZdS)�	BootTimesN�
/var/log/wtmprcCs||_||_||_dSr&)�	_filename�_boots_newer_than�_shutdowns_newer_than)rr�boots_newer_than�shutdowns_newer_thanrrrr$�s
zBootTimes.__init__cCs�g}g}t|jd��N}t|�}|j|_|j|_|��D]2}|j�	d�rMt
|j�}|jdkr;||jkr;|�
|�||_q|jdkrM||jkrM|�
|�||_qWd�||fS1s[wY||fS)N�rb�~�reboot�shutdown)rr�r�r��
_last_bootr��_last_shutdownr�rxrbrr�rz�append)r�reboot_times�shutdown_times�login_info_file�readerr��	timestamprrr�	get_times�s.






��
��zBootTimes.get_timescCs$|jdurtt��t��|_|jSr&)r�r�timerMr'rrr�get_last_boot_time�s
zBootTimes.get_last_boot_time)r�rr)rrr	r�r�r$r�r�rrrrr��s
�r�)rFr&)rrA�os.pathrrr��twisted.internet.utilsr�landscape.lib.encodingr�landscape.lib.timestampr�	Exceptionr�objectr
rErMrTrQrgr�r�rrrr�<module>s"0

%
Hacker Blog, Shell İndir, Sql İnjection, XSS Attacks, LFI Attacks, Social Hacking, Exploit Bot, Proxy Tools, Web Shell, PHP Shell, Alfa Shell İndir, Hacking Training Set, DDoS Script, Denial Of Service, Botnet, RFI Attacks, Encryption
Telegram @BIBIL_0DAY