/
system.py
157 lines (135 loc) · 5.06 KB
/
system.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
__author__ = 'Yonatan'
import psutil, subprocess
from ctypes import *
from cpuinfo import cpuinfo
from _winreg import *
def bytes2human(n):
symbols = ('KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'Z', 'Y')
prefix = {}
for i, s in enumerate(symbols):
prefix[s] = 1 << (i + 1) * 10
for s in reversed(symbols):
if n >= prefix[s]:
value = float(n) / prefix[s]
return '%.1f%s' % (value, s)
return "%sB" % n
def bytes2mega(n):
mb = 1 << 20
value = float(n) / mb
return round(value,2)
class cpu:
name = ''
utilization = ''
num_proccess = 0
def __init__(self):
info = cpuinfo.get_cpu_info()
self.name = info['brand']
self.num_proccess = psutil.cpu_count()
self.utilization = self.utilization_update()
def utilization_update(self):
return int(round(psutil.cpu_percent(interval=0.9)))
def end(self):
pass
class memory:
total = ''
available = ''
precent = ''
used = ''
free = ''
def __init__(self):
(total,available,precent,used, free) = psutil.virtual_memory()
self.total = total
self.available = available
self.precent = int(precent)
self.used = used
self.free = free
def end(self):
pass
class disk:
# ---------------> Computer Devices <--------------- #
devices = [] # Contains the computer's devices. Such as: C:\\, D:\\ ...
mountpoint = [] # Where the devices are located (devices path).
fstype = [] # Is a string which varies depending on the platform.
device_type = [] # Fixed devices (Hardware...) or Removable devices (DVD, DiskOnKey...).
os_name = '' # Operation system name. Windows 10, Windows 8.1, Windows 8 ...
# ---------------> Devices Information <--------------- #
total = [] # Total disk space.
used = [] # Used space.
free = [] # Free space.
percent = [] # percent of used disk.
def __init__(self):
self.devices = [disk.device for disk in psutil.disk_partitions()]
self.mountpoint = [disk.mountpoint for disk in psutil.disk_partitions()]
self.fstype = [disk.fstype for disk in psutil.disk_partitions()]
self.device_type = [self.GetDriveType(path) for path in self.devices]
self.os_name = self.get_os_name()
for path in self.mountpoint:
self.total.append(bytes2mega(psutil.disk_usage(path).total))
self.used.append(bytes2human(psutil.disk_usage(path).used))
self.free.append(bytes2human(psutil.disk_usage(path).free))
self.percent.append(str(psutil.disk_usage(path).percent)+'%')
def GetDriveType(self,path):
type_dict = {0: 'Unknown drive',
1: 'Path is invalid',
2: 'Removable drive',
3: 'Fixed drive',
4: 'Remote drive',
5: 'CD-ROM',
6: 'RAM-Disk'}
type = windll.Kernel32.GetDriveTypeA(path)
return type_dict[type]
def get_os_name(self):
root_dict = {
"HKEY_CLASSES_ROOT": HKEY_CLASSES_ROOT,
"HKEY_CURRENT_USER" : HKEY_CURRENT_USER,
"HKEY_LOCAL_MACHINE" : HKEY_LOCAL_MACHINE,
"HKEY_USERS" : HKEY_USERS,
"HKEY_CURRENT_CONFIG" : HKEY_CURRENT_CONFIG
}
root = root_dict['HKEY_LOCAL_MACHINE']
path = 'SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion'
key_hdl = CreateKey(root,path)
num_subkeys, num_values, last_modified = QueryInfoKey(key_hdl)
for i in range(num_values):
v_name, v_data, d_type = EnumValue(key_hdl,i)
if v_name == 'ProductName': return v_data
def end(self):
pass
class network:
ipconfig = {}
def __init__(self):
cmd = ["ipconfig","/all"]
log = open('log.txt','w')
proc = subprocess.Popen(cmd,0,None,None,log,log)
proc.wait()
ip_values = {}
titles = []
log = open('log.txt', 'r')
for line in log.readlines():
if line.find('adapter') > -1:
titles.append(line.strip())
#First dict Keys decleration
for t in titles:
self.ipconfig[t] = None
log = open('log.txt', 'r')
log = log.read().split('\n')
# Taking the title's data from ipconfig
for i in range(len(log)-3):
if log[i] is '':
i+=1
if log[i] in [t for t in titles]:
cat = log[i]
i+=1
if log[i] is '':
i+=1
while log[i] != '':
line = log[i].split("\n")
for l in line:
y = l.split(":", 1)
y[0] = y[0].replace('.','').strip()
ip_values[y[0]] = y[1]
i+=1
self.ipconfig[cat] = ip_values
ip_values = {}
def end(self):
pass