Skip to content

Commit 43491b0

Browse files
committed
added usb and disk devices list data
1 parent 181f7d9 commit 43491b0

8 files changed

+94
-0
lines changed

README.md

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ All the information used in this library is the same information handled by both
2424
- **Processor information** (from /proc/cpuinfo and /proc/stat)
2525
- **System memory information** (from /proc/meminfo)
2626
- **Network information** (from /proc/net/dev)
27+
- **USB devices** (from /dev/input/by-id)
28+
- **Disk devices** (from /dev/disk/by-id)
2729

2830
# Why use this library instead of others?
2931

@@ -276,3 +278,49 @@ As far as execution and data collection are concerned, we have:
276278
>>> netmon.NETmon().data()
277279
{'docker0': {'receive': {'bytes': 0, 'packets': 0, 'errs': 0, 'drop': 0, 'fifo': 0, 'frame': 0, 'compressed': 0, 'multicast': 0}, 'transmit': {'bytes': 0, 'packets': 0, 'errs': 0, 'drop': 0, 'fifo': 0, 'colls': 0, 'carrier': 0}}, ' lo': {'receive': {'bytes': 1505999, 'packets': 13803, 'errs': 0, 'drop': 0, 'fifo': 0, 'frame': 0, 'compressed': 0, 'multicast': 0}, 'transmit': {'bytes': 13803, 'packets': 0, 'errs': 0, 'drop': 0, 'fifo': 0, 'colls': 0, 'carrier': 0}}, 'enp37s0': {'receive': {'bytes': 134343470, 'packets': 155096, 'errs': 0, 'drop': 0, 'fifo': 0, 'frame': 0, 'compressed': 0, 'multicast': 1489}, 'transmit': {'bytes': 131526, 'packets': 0, 'errs': 0, 'drop': 0, 'fifo': 0, 'colls': 0, 'carrier': 0}}}
278280
```
281+
282+
## USB devices:
283+
284+
- **Print the information**
285+
286+
```python
287+
>>> import usb_devices
288+
>>> usb_devices.Devices().print_data()
289+
usb-Logitech_Gaming_Mouse_G300-mouse
290+
usb-Logitech_Gaming_Mouse_G300-if01
291+
usb-Logitech_Gaming_Mouse_G300
292+
usb-CHICONY_USB_Keyboard
293+
```
294+
295+
- **Extract the information in a dictionary**
296+
297+
```python
298+
>>> import usb_devices
299+
>>> usb_devices.Devices().data()
300+
['usb-Logitech_Gaming_Mouse_G300-mouse', 'usb-Logitech_Gaming_Mouse_G300-if01', 'usb-Logitech_Gaming_Mouse_G300', 'usb-CHICONY_USB_Keyboard']
301+
```
302+
303+
## Disks devices:
304+
305+
- **Print the information**
306+
307+
```python
308+
>>> import disk_devices
309+
>>> disk_devices.Devices().print_data()
310+
usb-TOSHIBA_TransMemory_0060E056B626E22180003A1B-0:0
311+
wwn-0x50014ee20b769657
312+
ata-TOSHIBA-TL100_27NB51GCKSZU
313+
ata-WDC_WD3200BEVT-22ZCT0_WD-WXEY08F45384
314+
wwn-0x50014ee202380e97
315+
wwn-0x500080dc007530e0
316+
ata-WDC_WD20EZRX-22D8PB0_WD-WCC4M1ZJ83JD
317+
```
318+
319+
- **Extract the information in a dictionary**
320+
321+
```python
322+
>>> import disk_devices
323+
>>> disk_devices.Devices().data()
324+
['usb-TOSHIBA_TransMemory_0060E056B626E22180003A1B-0:0', 'wwn-0x50014ee20b769657', 'ata-TOSHIBA-TL100_27NB51GCKSZU', 'ata-WDC_WD3200BEVT-22ZCT0_WD-WXEY08F45384', 'wwn-0x50014ee202380e97', 'wwn-0x500080dc007530e0', 'ata-WDC_WD20EZRX-22D8PB0_WD-WCC4M1ZJ83JD']
325+
326+
```
937 Bytes
Binary file not shown.
938 Bytes
Binary file not shown.

src/disk_devices.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
from os import listdir
2+
3+
class Devices():
4+
5+
def __init__(self):
6+
7+
self.path = '/dev/disk/by-id'
8+
9+
def data(self):
10+
11+
devices = list(map(lambda data: data.split('-part')[0], listdir(self.path)))
12+
return list(set(devices))
13+
14+
def print_data(self):
15+
16+
for device in self.data():
17+
print(device)
18+
19+
# Uncomment the following sentence to get a json from the data
20+
#print(Devices().data())
21+
# Uncomment the following sentence to print the data
22+
#Devices().print_data()

src/hwmon.pyc

-2.57 KB
Binary file not shown.

src/usb_devices.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
from os import listdir
2+
3+
class Devices():
4+
5+
def __init__(self):
6+
7+
self.path = '/dev/input/by-id'
8+
9+
def data(self):
10+
11+
devices = list(map(lambda data: data.split('-event')[0], listdir(self.path)))
12+
return list(set(devices))
13+
14+
def print_data(self):
15+
16+
for device in self.data():
17+
print(device)
18+
19+
# Uncomment the following sentence to get a json from the data
20+
#print(Devices().data())
21+
# Uncomment the following sentence to print the data
22+
#Devices().print_data()

src/utils.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ def is_vm():
2323
try:
2424
subprocess.check_output('dmesg |grep -i hypervisor', shell=True)
2525
print("Running under VM environment")
26+
print("""Information displayed by Hwmon when running
27+
the code in a virtual machine may be incomplete""")
2628
return True
2729
except:
2830
print("Not running under VM environment")

src/utils.pyc

-944 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)