1use networkmanager::devices::{Any, Bluetooth, Device, Wired, Wireless};
2use networkmanager::{Error, NetworkManager};
3
4use dbus::blocking::Connection;
5
6fn main() -> Result<(), Error> {
7 let dbus_connection = Connection::new_system()?;
8
9 let nm = NetworkManager::new(&dbus_connection);
10
11 for dev in nm.get_devices()? {
12 match dev {
13 Device::Ethernet(x) => {
14 println!("Is autoconnected: {:?}", x.autoconnect()?);
15 println!("Speed: {:?}", x.speed()?);
16 println!("S390 Subchannels: {:?}", x.s390_subchannels()?);
17 println!("Carrier: {:?}", x.carrier()?);
18 let conf = x.ip4_config()?;
19 println!("Gateway: {:?}", conf.gateway()?);
20 let con = x.active_connection()?;
21 println!("Connection id: {}", con.id()?);
22 }
23 Device::WiFi(x) => {
24 println!("Bitrate: {:?}", x.bitrate()?);
25 x.request_scan(std::collections::HashMap::new())?;
26 for ap in x.get_all_access_points()? {
27 println!("SSID: {:?}", ap.ssid()?);
28 }
29 }
30 Device::Bluetooth(x) => {
31 println!("Name: {:?}", x.name()?);
32 println!("Capabilities: {}", Bluetooth::hw_address(&x)?);
33 }
34 _ => {}
35 }
36 }
37
38 let eth0 = nm.get_device_by_ip_iface("eth0")?;
39 match eth0 {
40 Device::Ethernet(x) => {
41 println!("Speed: {:?}", x.speed()?);
48 }
49 _ => {}
50 }
51
52 Ok(())
53}