networkmanager-rs

Crates.io docs.rs CI

A NetworkManager API library using the D-Bus message bus system

Status

This project is still under development. Currently implemented parts can be found in the docs.

Usage

Add networkmanager to your Cargo.toml with:

toml [dependencies] networkmanager = "0.3"

Example

```rust,no_run use networkmanager::devices::{Any, Device, Wired, Wireless}; use networkmanager::{Error, NetworkManager}; use networkmanager::dbus::DBusConnection;

fn main() -> Result<(), Error> { let dbus_connection = DBusConnection::new()?;

let nm = NetworkManager::new(&dbus_connection);

for dev in nm.get_devices()? {
    match dev {
        Device::Ethernet(x) => {
            println!("Is autoconnected: {:?}", x.autoconnect()?);
            println!("Speed: {:?}", x.speed()?);
            println!("S390 Subchannels: {:?}", x.s390_subchannels()?);
            println!("Carrier: {:?}", x.carrier()?);
        }
        Device::WiFi(x) => {
            println!("Access Point: {:?}", x.access_points()?);
        }
        _ => {}
    }
}

let enp0s2 = nm.get_device_by_ip_iface("enp0s2")?;
match enp0s2 {
    Device::Ethernet(x) => {
        // NetworkManager >= 1.24
        // println!("Hardware Address: {:?}", Any::hw_address(&x)?);

        // NetworkManager < 1.24
        // println!("Hardware Address: {:?}", Wired::hw_address(&x)?);

        println!("Speed: {:?}", x.speed()?);
    }
    _ => {}
}

Ok(())

} ```

Build prerequisites

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.