isimud 0.3__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- isimud/__init__.py +12 -0
- isimud/isimud.py +171 -0
- isimud-0.3.dist-info/METADATA +47 -0
- isimud-0.3.dist-info/RECORD +7 -0
- isimud-0.3.dist-info/WHEEL +5 -0
- isimud-0.3.dist-info/licenses/LICENSE +21 -0
- isimud-0.3.dist-info/top_level.txt +1 -0
isimud/__init__.py
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
|
|
3
|
+
from isimud.isimud import get_loopback_interface
|
|
4
|
+
from isimud.isimud import get_eth_interfaces
|
|
5
|
+
from isimud.isimud import get_wifi_interfaces
|
|
6
|
+
from isimud.isimud import interface_operstate
|
|
7
|
+
from isimud.isimud import interface_mac_address
|
|
8
|
+
from isimud.isimud import interface_recv_bytes
|
|
9
|
+
from isimud.isimud import interface_sent_bytes
|
|
10
|
+
from isimud.isimud import access_point_essid
|
|
11
|
+
from isimud.isimud import access_point_signal_percent
|
|
12
|
+
from isimud.isimud import access_point_mac_address
|
isimud/isimud.py
ADDED
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
|
|
3
|
+
"""
|
|
4
|
+
Package to get commonly used details of the network interface
|
|
5
|
+
and access point you are using.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from typing import Any, List, Optional
|
|
9
|
+
|
|
10
|
+
from netifaces import interfaces
|
|
11
|
+
|
|
12
|
+
from pyroute2 import IPRoute
|
|
13
|
+
from pyroute2.iwutil import IW
|
|
14
|
+
|
|
15
|
+
from subprocess import DEVNULL, PIPE, run
|
|
16
|
+
|
|
17
|
+
from re import findall, search, I
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def get_loopback_interface() -> List[str]:
|
|
21
|
+
""" Return a list of loopback interfaces (ideally one). """
|
|
22
|
+
return [
|
|
23
|
+
interface for interface in interfaces(
|
|
24
|
+
) if interface.startswith("lo")
|
|
25
|
+
]
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def get_eth_interfaces() -> List[str]:
|
|
29
|
+
""" Return a list of ethernet interfaces (ideally one). """
|
|
30
|
+
return [
|
|
31
|
+
interface for interface in interfaces(
|
|
32
|
+
) if interface.startswith("en")
|
|
33
|
+
]
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def get_wifi_interfaces() -> List[str]:
|
|
37
|
+
""" Return list of wifi interfaces (ideally one). """
|
|
38
|
+
return [
|
|
39
|
+
interface for interface in interfaces(
|
|
40
|
+
) if interface.startswith("wl")
|
|
41
|
+
]
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def __get_iwconfig_output(interface: str) -> str:
|
|
45
|
+
""" Return iwconfig {interface} output. """
|
|
46
|
+
return run(
|
|
47
|
+
f"iwconfig {interface}",
|
|
48
|
+
shell=True,
|
|
49
|
+
stdout=PIPE,
|
|
50
|
+
stderr=DEVNULL
|
|
51
|
+
).stdout.decode()
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
def __winterface_name_to_device_dict(interface: str) -> Any:
|
|
55
|
+
""" Return a dict containing device details (from pyroute2.IW). """
|
|
56
|
+
with IW() as iw:
|
|
57
|
+
list_dev_dict = iw.list_dev()
|
|
58
|
+
for device_dict in list_dev_dict:
|
|
59
|
+
if device_dict["attrs"][1][1] == interface:
|
|
60
|
+
return device_dict
|
|
61
|
+
return None
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
def __get_interface_number(interface: str) -> Optional[int]:
|
|
65
|
+
""" Return the interface number (from pyroute2.IPRoute). """
|
|
66
|
+
with IPRoute() as ipr:
|
|
67
|
+
interface_number_list = ipr.link_lookup(ifname=interface)
|
|
68
|
+
if len(interface_number_list) > 0:
|
|
69
|
+
return interface_number_list[0]
|
|
70
|
+
return None
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
def __get_interface_stats(interface: str) -> Any:
|
|
74
|
+
""" Return the interface stats dict (from pyroute2.IPRoute). """
|
|
75
|
+
with IPRoute() as ipr:
|
|
76
|
+
return ipr.get_links(ifname=interface)[0]["attrs"][20][1]
|
|
77
|
+
return None
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
def interface_operstate(interface: str) -> Optional[str]:
|
|
81
|
+
"""
|
|
82
|
+
Get the operstate of an interface.
|
|
83
|
+
|
|
84
|
+
:param interface: str: Network interface.
|
|
85
|
+
|
|
86
|
+
"""
|
|
87
|
+
interface_number = __get_interface_number(interface)
|
|
88
|
+
if interface_number:
|
|
89
|
+
with IPRoute() as ipr:
|
|
90
|
+
if interface_number in ipr.link_lookup(operstate="UP"):
|
|
91
|
+
return "UP"
|
|
92
|
+
elif interface_number in ipr.link_lookup(operstate="DOWN"):
|
|
93
|
+
return "DOWN"
|
|
94
|
+
elif interface_number in ipr.link_lookup(operstate="UNKNOWN"):
|
|
95
|
+
return "UNKNOWN"
|
|
96
|
+
return None
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
def interface_mac_address(interface: str) -> str:
|
|
100
|
+
"""
|
|
101
|
+
Get the MAC address of an interface.
|
|
102
|
+
|
|
103
|
+
:param interface: str: Network interface.
|
|
104
|
+
|
|
105
|
+
"""
|
|
106
|
+
with IPRoute() as ipr:
|
|
107
|
+
return ipr.get_links(ifname=interface)[0]["attrs"][18][1]
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
def interface_recv_bytes(interface: str) -> int:
|
|
111
|
+
"""
|
|
112
|
+
Get the recv bytes of an interface.
|
|
113
|
+
|
|
114
|
+
:param interface: str: Network interface.
|
|
115
|
+
|
|
116
|
+
"""
|
|
117
|
+
return __get_interface_stats(interface)["rx_bytes"]
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
def interface_sent_bytes(interface: str) -> int:
|
|
121
|
+
"""
|
|
122
|
+
Get the sent bytes of an interface.
|
|
123
|
+
|
|
124
|
+
:param interface: str: Network interface.
|
|
125
|
+
|
|
126
|
+
"""
|
|
127
|
+
return __get_interface_stats(interface)["tx_bytes"]
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
def access_point_essid(interface: str) -> Optional[str]:
|
|
131
|
+
"""
|
|
132
|
+
Get the AP ESSID.
|
|
133
|
+
|
|
134
|
+
:param interface: str: Network interface.
|
|
135
|
+
|
|
136
|
+
"""
|
|
137
|
+
device_dict = __winterface_name_to_device_dict(interface)
|
|
138
|
+
if device_dict:
|
|
139
|
+
if len(device_dict["attrs"]) >= 13:
|
|
140
|
+
if device_dict["attrs"][12][0] == "NL80211_ATTR_SSID":
|
|
141
|
+
return device_dict["attrs"][12][1]
|
|
142
|
+
return None
|
|
143
|
+
|
|
144
|
+
|
|
145
|
+
def access_point_signal_percent(interface: str) -> Optional[int]:
|
|
146
|
+
"""
|
|
147
|
+
Get the AP Signal percent.
|
|
148
|
+
|
|
149
|
+
:param interface: str: Network interface.
|
|
150
|
+
|
|
151
|
+
"""
|
|
152
|
+
iwconfig_output = __get_iwconfig_output(interface)
|
|
153
|
+
res = findall(r"Link Quality=(\d*/\d*)", iwconfig_output)
|
|
154
|
+
if res != []:
|
|
155
|
+
signal = res[0].split("/")
|
|
156
|
+
return round(100 / int(signal[1]) * int(signal[0]))
|
|
157
|
+
return None
|
|
158
|
+
|
|
159
|
+
|
|
160
|
+
def access_point_mac_address(interface: str) -> Optional[str]:
|
|
161
|
+
"""
|
|
162
|
+
Get the AP MAC.
|
|
163
|
+
|
|
164
|
+
:param interface: str: Network interface.
|
|
165
|
+
|
|
166
|
+
"""
|
|
167
|
+
iwconfig_output = __get_iwconfig_output(interface)
|
|
168
|
+
res = search(r'([0-9A-F]{2}[:-]){5}([0-9A-F]{2})', iwconfig_output, I)
|
|
169
|
+
if res:
|
|
170
|
+
return res.group().lower()
|
|
171
|
+
return None
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: isimud
|
|
3
|
+
Version: 0.3
|
|
4
|
+
Summary: Package to get commonly used details of the network interface and access points you are using.
|
|
5
|
+
Author-email: "Carlos A. Planchón" <carlosandresplanchonprestes@gmail.com>
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Repository, https://github.com/carlosplanchon/isimud
|
|
8
|
+
Keywords: isimud,sensors,wifi,networking
|
|
9
|
+
Classifier: Intended Audience :: Developers
|
|
10
|
+
Classifier: Topic :: Software Development :: Build Tools
|
|
11
|
+
Classifier: Programming Language :: Python :: 3
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
18
|
+
Requires-Python: >=3.9
|
|
19
|
+
Description-Content-Type: text/markdown
|
|
20
|
+
License-File: LICENSE
|
|
21
|
+
Requires-Dist: netifaces
|
|
22
|
+
Requires-Dist: pyroute2
|
|
23
|
+
Dynamic: license-file
|
|
24
|
+
|
|
25
|
+
# Isimud
|
|
26
|
+
*Package to get commonly used details of the network interface and access points you are using.*
|
|
27
|
+
|
|
28
|
+
## Installation
|
|
29
|
+
### Install with uv:
|
|
30
|
+
```
|
|
31
|
+
uv add isimud
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
## Features
|
|
35
|
+
|
|
36
|
+
- Get loopback, ethernet and wifi interfaces.
|
|
37
|
+
- Get operstate, mac_address, recv and sent bytes of an interface.
|
|
38
|
+
- Get ESSID, signal percent and MAC address of an interface.
|
|
39
|
+
|
|
40
|
+
## Usage
|
|
41
|
+
```
|
|
42
|
+
In [3]: import isimud
|
|
43
|
+
|
|
44
|
+
In [4]: isimud.get_eth_interfaces()
|
|
45
|
+
|
|
46
|
+
Out[4]: ['enp9s0']
|
|
47
|
+
```
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
isimud/__init__.py,sha256=TOwrQvRMYsfdLZubUpoFQ9YSYrKioRMI3xZuSxuuQ5o,502
|
|
2
|
+
isimud/isimud.py,sha256=dL5yFmJaOfY6-mzqJWWmcj0oK66zuhaX0NHO1hFAolo,4573
|
|
3
|
+
isimud-0.3.dist-info/licenses/LICENSE,sha256=dUqwRhq9nAYp-zfLbCuFB1d_dlg7PjxGZzNMPCTaa0c,1076
|
|
4
|
+
isimud-0.3.dist-info/METADATA,sha256=DXGwQnS40yqdUCn_muc1hjnk6UjTFfg-j0yQ9BjILEM,1421
|
|
5
|
+
isimud-0.3.dist-info/WHEEL,sha256=wUyA8OaulRlbfwMtmQsvNngGrxQHAvkKcvRmdizlJi0,92
|
|
6
|
+
isimud-0.3.dist-info/top_level.txt,sha256=2j2M-w531jC5zFjlZ0QVnCnzdsiKNCgvoOdmT2T5_xg,7
|
|
7
|
+
isimud-0.3.dist-info/RECORD,,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2019 Carlos A. Planchón
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
isimud
|