ifpeek 1.0.0__tar.gz

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.
ifpeek-1.0.0/LICENSE ADDED
@@ -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.
ifpeek-1.0.0/PKG-INFO ADDED
@@ -0,0 +1,140 @@
1
+ Metadata-Version: 2.4
2
+ Name: ifpeek
3
+ Version: 1.0.0
4
+ Summary: Inspect Linux network interfaces, Wi-Fi state, routes, DNS, and network events from Python.
5
+ Author-email: "Carlos A. Planchón" <carlosandresplanchonprestes@gmail.com>
6
+ License-Expression: MIT
7
+ Project-URL: Homepage, https://github.com/carlosplanchon/ifpeek
8
+ Project-URL: Repository, https://github.com/carlosplanchon/ifpeek
9
+ Keywords: linux,networking,netlink,nl80211,pyroute2,wifi,network-interfaces
10
+ Classifier: Intended Audience :: Developers
11
+ Classifier: Intended Audience :: System Administrators
12
+ Classifier: Operating System :: POSIX :: Linux
13
+ Classifier: Topic :: System :: Networking
14
+ Classifier: Topic :: System :: Networking :: Monitoring
15
+ Classifier: Programming Language :: Python :: 3
16
+ Classifier: Programming Language :: Python :: 3.10
17
+ Classifier: Programming Language :: Python :: 3.11
18
+ Classifier: Programming Language :: Python :: 3.12
19
+ Classifier: Programming Language :: Python :: 3.13
20
+ Classifier: Programming Language :: Python :: 3.14
21
+ Requires-Python: >=3.10
22
+ Description-Content-Type: text/markdown
23
+ License-File: LICENSE
24
+ Requires-Dist: pyroute2
25
+ Provides-Extra: scan
26
+ Requires-Dist: jeepney>=0.8; extra == "scan"
27
+ Provides-Extra: dev
28
+ Requires-Dist: pytest>=9.1; extra == "dev"
29
+ Requires-Dist: pytest-cov>=7.1; extra == "dev"
30
+ Requires-Dist: jeepney>=0.8; extra == "dev"
31
+ Dynamic: license-file
32
+
33
+ # ifpeek
34
+
35
+ ![ifpeek](https://raw.githubusercontent.com/carlosplanchon/ifpeek/master/assets/banner.jpg)
36
+
37
+ [![CI](https://github.com/carlosplanchon/ifpeek/actions/workflows/ci.yml/badge.svg)](https://github.com/carlosplanchon/ifpeek/actions/workflows/ci.yml)
38
+ [![PyPI version](https://img.shields.io/pypi/v/ifpeek.svg)](https://pypi.org/project/ifpeek/)
39
+ [![Python versions](https://img.shields.io/pypi/pyversions/ifpeek.svg)](https://pypi.org/project/ifpeek/)
40
+ [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)
41
+ [![DeepWiki](https://deepwiki.com/badge.svg)](https://deepwiki.com/carlosplanchon/ifpeek)
42
+
43
+ *Inspect Linux network interfaces, Wi-Fi state, routes, DNS, and network events from Python.*
44
+
45
+ > **Linux only.** ifpeek relies on `pyroute2` (netlink), its single runtime dependency.
46
+
47
+ ## Installation
48
+
49
+ Requires **Python 3.10+** on **Linux**. Install with [uv](https://docs.astral.sh/uv/):
50
+
51
+ ```bash
52
+ uv add ifpeek # core (only dependency: pyroute2)
53
+ uv add "ifpeek[scan]" # + nearby Wi-Fi scanning (iwd / NetworkManager / wpa_supplicant)
54
+ ```
55
+
56
+ ## Features
57
+
58
+ Core facts (interfaces, Wi-Fi, routes, events) come from the kernel via `pyroute2` (netlink / nl80211):
59
+ no external tools, no root. DNS is read from `resolv.conf`, and the optional Wi-Fi scan uses D-Bus.
60
+
61
+ **Interfaces**
62
+ - List loopback / ethernet / wifi interfaces (classified by kernel type, not by name).
63
+ - Per interface: type, operational state, MAC, MTU, carrier, IPv4 / IPv6 addresses, traffic counters (bytes / packets / errors / drops), and throughput rate.
64
+
65
+ **Access point (Wi-Fi)**
66
+ - ESSID, BSSID, signal (dBm + %), plus the frequency and current bitrate of the associated AP.
67
+
68
+ **Host network**
69
+ - The default interface, default gateway (IPv4 / IPv6), and the configured DNS servers.
70
+
71
+ **Nearby Wi-Fi scan** *(optional, requires `ifpeek[scan]` + a running Wi-Fi daemon)*
72
+ - List nearby access points (SSID, signal, security) via **iwd, NetworkManager, or wpa_supplicant** over D-Bus, without root.
73
+
74
+ **Events**
75
+ - `watch()`: a live stream of link / address / route changes (netlink, no root), to react instead of poll.
76
+
77
+ ## Usage
78
+
79
+ ```python
80
+ import ifpeek
81
+
82
+ # --- interfaces ---
83
+ ifpeek.get_wifi_interfaces() # ['wlan0']
84
+ ifpeek.interface_type("docker0") # 'bridge'
85
+ ifpeek.interface_operstate("wlan0") # 'UP'
86
+ ifpeek.interface_mac_address("wlan0") # 'a1:b2:c3:d4:e5:f6'
87
+ ifpeek.interface_mtu("wlan0") # 1500
88
+ ifpeek.interface_ipv4_addresses("wlan0") # ['192.168.1.42']
89
+ ifpeek.interface_stats("wlan0").rx_packets # 51702404
90
+ ifpeek.interface_rate("wlan0") # InterfaceRate(rx_bytes_per_sec=…, tx_bytes_per_sec=…)
91
+
92
+ # --- access point (Wi-Fi) ---
93
+ ifpeek.access_point_essid("wlan0") # 'MyNetwork'
94
+ ifpeek.access_point_mac_address("wlan0") # 'aa:bb:cc:dd:ee:ff' (BSSID)
95
+ ifpeek.access_point_signal_dbm("wlan0") # -47
96
+ ifpeek.access_point_frequency("wlan0") # 5280 (MHz)
97
+ ifpeek.access_point_bitrate("wlan0") # 866.7 (Mbps)
98
+
99
+ # --- host network ---
100
+ ifpeek.default_interface() # 'wlan0'
101
+ ifpeek.default_gateway_ipv4() # '192.168.1.1'
102
+ ifpeek.dns_servers() # ['192.168.1.1']
103
+ ```
104
+
105
+ ### Nearby Wi-Fi scan (optional)
106
+
107
+ Requires the `scan` extra and a running Wi-Fi daemon: [iwd](https://iwd.wiki.kernel.org/),
108
+ [NetworkManager](https://networkmanager.dev/), or [wpa_supplicant](https://w1.fi/wpa_supplicant/),
109
+ auto-detected. The caller must be allowed on the daemon's D-Bus (e.g. be in the `wheel` / `network` group):
110
+
111
+ ```bash
112
+ uv add "ifpeek[scan]"
113
+ ```
114
+
115
+ ```python
116
+ import ifpeek
117
+
118
+ for ap in ifpeek.scan_access_points(): # strongest signal first
119
+ print(ap.ssid, ap.bssid, ap.signal_percent, ap.security)
120
+ # AccessPoint(ssid='MyNetwork', bssid='aa:bb:cc:dd:ee:ff', frequency=5180,
121
+ # signal_dbm=None, signal_percent=100, security='psk', connected=True)
122
+ ```
123
+
124
+ `signal_percent` (0-100) is always present. `signal_dbm` is usually filled by iwd / wpa_supplicant
125
+ and `None` on NetworkManager (percentage-only); `bssid` and `frequency` are usually filled by
126
+ NetworkManager / wpa_supplicant and `None` on iwd (its scan is network-centric).
127
+
128
+ > **Backend status:** the **iwd** backend is verified against a live daemon. The **NetworkManager** and
129
+ > **wpa_supplicant** backends are implemented against their documented D-Bus APIs and unit-tested, but not
130
+ > yet exercised against a live daemon. Bug reports welcome.
131
+
132
+ ### Watch for changes (event stream)
133
+
134
+ ```python
135
+ import ifpeek
136
+
137
+ for event in ifpeek.watch(): # blocks; yields as things change
138
+ print(event.kind, event.action, event.interface, event.detail)
139
+ # NetworkEvent(kind='link', action='new', interface='wlan0', index=4, detail={'operstate': 'DOWN'})
140
+ ```
ifpeek-1.0.0/README.md ADDED
@@ -0,0 +1,108 @@
1
+ # ifpeek
2
+
3
+ ![ifpeek](https://raw.githubusercontent.com/carlosplanchon/ifpeek/master/assets/banner.jpg)
4
+
5
+ [![CI](https://github.com/carlosplanchon/ifpeek/actions/workflows/ci.yml/badge.svg)](https://github.com/carlosplanchon/ifpeek/actions/workflows/ci.yml)
6
+ [![PyPI version](https://img.shields.io/pypi/v/ifpeek.svg)](https://pypi.org/project/ifpeek/)
7
+ [![Python versions](https://img.shields.io/pypi/pyversions/ifpeek.svg)](https://pypi.org/project/ifpeek/)
8
+ [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)
9
+ [![DeepWiki](https://deepwiki.com/badge.svg)](https://deepwiki.com/carlosplanchon/ifpeek)
10
+
11
+ *Inspect Linux network interfaces, Wi-Fi state, routes, DNS, and network events from Python.*
12
+
13
+ > **Linux only.** ifpeek relies on `pyroute2` (netlink), its single runtime dependency.
14
+
15
+ ## Installation
16
+
17
+ Requires **Python 3.10+** on **Linux**. Install with [uv](https://docs.astral.sh/uv/):
18
+
19
+ ```bash
20
+ uv add ifpeek # core (only dependency: pyroute2)
21
+ uv add "ifpeek[scan]" # + nearby Wi-Fi scanning (iwd / NetworkManager / wpa_supplicant)
22
+ ```
23
+
24
+ ## Features
25
+
26
+ Core facts (interfaces, Wi-Fi, routes, events) come from the kernel via `pyroute2` (netlink / nl80211):
27
+ no external tools, no root. DNS is read from `resolv.conf`, and the optional Wi-Fi scan uses D-Bus.
28
+
29
+ **Interfaces**
30
+ - List loopback / ethernet / wifi interfaces (classified by kernel type, not by name).
31
+ - Per interface: type, operational state, MAC, MTU, carrier, IPv4 / IPv6 addresses, traffic counters (bytes / packets / errors / drops), and throughput rate.
32
+
33
+ **Access point (Wi-Fi)**
34
+ - ESSID, BSSID, signal (dBm + %), plus the frequency and current bitrate of the associated AP.
35
+
36
+ **Host network**
37
+ - The default interface, default gateway (IPv4 / IPv6), and the configured DNS servers.
38
+
39
+ **Nearby Wi-Fi scan** *(optional, requires `ifpeek[scan]` + a running Wi-Fi daemon)*
40
+ - List nearby access points (SSID, signal, security) via **iwd, NetworkManager, or wpa_supplicant** over D-Bus, without root.
41
+
42
+ **Events**
43
+ - `watch()`: a live stream of link / address / route changes (netlink, no root), to react instead of poll.
44
+
45
+ ## Usage
46
+
47
+ ```python
48
+ import ifpeek
49
+
50
+ # --- interfaces ---
51
+ ifpeek.get_wifi_interfaces() # ['wlan0']
52
+ ifpeek.interface_type("docker0") # 'bridge'
53
+ ifpeek.interface_operstate("wlan0") # 'UP'
54
+ ifpeek.interface_mac_address("wlan0") # 'a1:b2:c3:d4:e5:f6'
55
+ ifpeek.interface_mtu("wlan0") # 1500
56
+ ifpeek.interface_ipv4_addresses("wlan0") # ['192.168.1.42']
57
+ ifpeek.interface_stats("wlan0").rx_packets # 51702404
58
+ ifpeek.interface_rate("wlan0") # InterfaceRate(rx_bytes_per_sec=…, tx_bytes_per_sec=…)
59
+
60
+ # --- access point (Wi-Fi) ---
61
+ ifpeek.access_point_essid("wlan0") # 'MyNetwork'
62
+ ifpeek.access_point_mac_address("wlan0") # 'aa:bb:cc:dd:ee:ff' (BSSID)
63
+ ifpeek.access_point_signal_dbm("wlan0") # -47
64
+ ifpeek.access_point_frequency("wlan0") # 5280 (MHz)
65
+ ifpeek.access_point_bitrate("wlan0") # 866.7 (Mbps)
66
+
67
+ # --- host network ---
68
+ ifpeek.default_interface() # 'wlan0'
69
+ ifpeek.default_gateway_ipv4() # '192.168.1.1'
70
+ ifpeek.dns_servers() # ['192.168.1.1']
71
+ ```
72
+
73
+ ### Nearby Wi-Fi scan (optional)
74
+
75
+ Requires the `scan` extra and a running Wi-Fi daemon: [iwd](https://iwd.wiki.kernel.org/),
76
+ [NetworkManager](https://networkmanager.dev/), or [wpa_supplicant](https://w1.fi/wpa_supplicant/),
77
+ auto-detected. The caller must be allowed on the daemon's D-Bus (e.g. be in the `wheel` / `network` group):
78
+
79
+ ```bash
80
+ uv add "ifpeek[scan]"
81
+ ```
82
+
83
+ ```python
84
+ import ifpeek
85
+
86
+ for ap in ifpeek.scan_access_points(): # strongest signal first
87
+ print(ap.ssid, ap.bssid, ap.signal_percent, ap.security)
88
+ # AccessPoint(ssid='MyNetwork', bssid='aa:bb:cc:dd:ee:ff', frequency=5180,
89
+ # signal_dbm=None, signal_percent=100, security='psk', connected=True)
90
+ ```
91
+
92
+ `signal_percent` (0-100) is always present. `signal_dbm` is usually filled by iwd / wpa_supplicant
93
+ and `None` on NetworkManager (percentage-only); `bssid` and `frequency` are usually filled by
94
+ NetworkManager / wpa_supplicant and `None` on iwd (its scan is network-centric).
95
+
96
+ > **Backend status:** the **iwd** backend is verified against a live daemon. The **NetworkManager** and
97
+ > **wpa_supplicant** backends are implemented against their documented D-Bus APIs and unit-tested, but not
98
+ > yet exercised against a live daemon. Bug reports welcome.
99
+
100
+ ### Watch for changes (event stream)
101
+
102
+ ```python
103
+ import ifpeek
104
+
105
+ for event in ifpeek.watch(): # blocks; yields as things change
106
+ print(event.kind, event.action, event.interface, event.detail)
107
+ # NetworkEvent(kind='link', action='new', interface='wlan0', index=4, detail={'operstate': 'DOWN'})
108
+ ```
@@ -0,0 +1,35 @@
1
+ #!/usr/bin/env python3
2
+
3
+ from ifpeek.ifpeek import get_loopback_interface
4
+ from ifpeek.ifpeek import get_eth_interfaces
5
+ from ifpeek.ifpeek import get_wifi_interfaces
6
+ from ifpeek.ifpeek import interface_operstate
7
+ from ifpeek.ifpeek import interface_mac_address
8
+ from ifpeek.ifpeek import interface_recv_bytes
9
+ from ifpeek.ifpeek import interface_sent_bytes
10
+ from ifpeek.ifpeek import access_point_essid
11
+ from ifpeek.ifpeek import access_point_signal_dbm
12
+ from ifpeek.ifpeek import access_point_signal_percent
13
+ from ifpeek.ifpeek import access_point_mac_address
14
+ from ifpeek.ifpeek import access_point_frequency
15
+ from ifpeek.ifpeek import access_point_bitrate
16
+
17
+ from ifpeek.ifpeek import interface_type
18
+ from ifpeek.ifpeek import interface_mtu
19
+ from ifpeek.ifpeek import interface_has_carrier
20
+ from ifpeek.ifpeek import interface_stats
21
+ from ifpeek.ifpeek import InterfaceStats
22
+ from ifpeek.ifpeek import interface_rate
23
+ from ifpeek.ifpeek import InterfaceRate
24
+ from ifpeek.ifpeek import interface_ipv4_addresses
25
+ from ifpeek.ifpeek import interface_ipv6_addresses
26
+ from ifpeek.ifpeek import default_gateway_ipv4
27
+ from ifpeek.ifpeek import default_gateway_ipv6
28
+ from ifpeek.ifpeek import default_interface
29
+ from ifpeek.ifpeek import dns_servers
30
+
31
+ from ifpeek.ifpeek import watch
32
+ from ifpeek.ifpeek import NetworkEvent
33
+
34
+ from ifpeek.scan import scan_access_points
35
+ from ifpeek.scan import AccessPoint