A Rust library for managing NetworkManager connections over D-Bus.
See the codenmrs 🦀
An async-first Rust API for NetworkManager over D-Bus. The goal is to provide a safe and simple high-level API for managing Wi-Fi connections on Linux systems, built on zbus for reliable D-Bus communication.
Please consider joining the Discord. It's a welcoming community to both developers who want to contribute and/or learn about and discuss nmrs as well as users that would like to be engaged with the development process.
The best way to get started with nmrs is the User Guide, which includes comprehensive tutorials and examples. For detailed API information, see the API documentation.
We'll create a simple example that scans for available networks and connects to one. Note that these examples require NetworkManager to be running on your Linux system with D-Bus access, obviously.
Scan for and display available Wi-Fi networks:
use nmrs::NetworkManager;
#[tokio::main]
async fn main() -> nmrs::Result<()> {
let nm = NetworkManager::new().await?;
// Scan for networks
let networks = nm.list_networks(None).await?;
for net in networks {
println!(
"{} - Signal: {}%, Security: {:?}",
net.ssid,
net.strength.unwrap_or(0),
net.security
);
}
Ok(())
}
Connect to a WPA-PSK protected network:
use nmrs::{NetworkManager, WifiSecurity};
#[tokio::main]
async fn main() -> nmrs::Result<()> {
let nm = NetworkManager::new().await?;
// Connect to a network
nm.connect("MyNetwork", None, WifiSecurity::WpaPsk {
psk: "password123".into()
}).await?;
// Check current connection
if let Some(ssid) = nm.current_ssid().await {
println!("Connected to: {}", ssid);
}
Ok(())
}
All operations return Result<T, ConnectionError> with specific error variants:
use nmrs::{NetworkManager, WifiSecurity, ConnectionError};
#[tokio::main]
async fn main() -> nmrs::Result<()> {
let nm = NetworkManager::new().await?;
match nm.connect("MyNetwork", None, WifiSecurity::WpaPsk {
psk: "wrong_password".into()
}).await {
Ok(_) => println!("Connected successfully"),
Err(ConnectionError::AuthFailed) => eprintln!("Authentication failed - wrong password"),
Err(ConnectionError::NotFound) => eprintln!("Network not found or out of range"),
Err(ConnectionError::Timeout) => eprintln!("Connection timed out"),
Err(e) => eprintln!("Error: {}", e),
}
Ok(())
}
To follow and/or discuss the development of nmrs, you can join the public Discord channel.
|
cosmic-settings by @pop-os |
cosmic-applets by @pop-os |
|
nmrs-tui by @y2w8 |
gaypanel by @pastthepixels |
|
nmrs-gui by @freedesktop-rs |
android-auto by @uglyoldbob |
If something is missing that you'd like to see, please file a PR or issue, adding it to this roadmap.
nm.wifi("wlan0")WifiConnectionBuilder::hiddentry_connect / try_connect_to_bssidconnect() (directed scan for a non-broadcast SSID).ovpn import supportconnect_by_uuid / disconnect_by_uuidnetwork_events() / settings_events() streams and point-in-time snapshot()ConnectionBuilder, add_connection / add_and_activate_connection, and raw zbus accessAdapter1 / Device1Contributions are welcome. Please read CONTRIBUTING.md for guidelines.
Environmental tests are opt-in and ignored by a normal cargo test, so local
test runs never probe the host NetworkManager implicitly. Use
docker compose run --build --rm test-integration for isolated settings,
NetworkManager-routed secrets, native WireGuard activation, and veth-backed
wired DHCP lifecycles, or
test-wifi-integration with two mac80211_hwsim radios for the deterministic
WPA/DHCP and callback-monitor lifecycle. See the contributing guide for the
exact commands.
This project is dual-licensed under either of the following licenses, at your option:
You may use, copy, modify, and distribute this software under the terms of either license.
See the following files for full license texts:
Thank you to everyone who has helped build, test, document, and review nmrs.
(top 30 of 34)
Rust
97.8%
Shell
1.4%
A Rust library for managing NetworkManager connections over D-Bus.
See the codenmrs 🦀
An async-first Rust API for NetworkManager over D-Bus. The goal is to provide a safe and simple high-level API for managing Wi-Fi connections on Linux systems, built on zbus for reliable D-Bus communication.
Please consider joining the Discord. It's a welcoming community to both developers who want to contribute and/or learn about and discuss nmrs as well as users that would like to be engaged with the development process.
The best way to get started with nmrs is the User Guide, which includes comprehensive tutorials and examples. For detailed API information, see the API documentation.
We'll create a simple example that scans for available networks and connects to one. Note that these examples require NetworkManager to be running on your Linux system with D-Bus access, obviously.
Scan for and display available Wi-Fi networks:
use nmrs::NetworkManager;
#[tokio::main]
async fn main() -> nmrs::Result<()> {
let nm = NetworkManager::new().await?;
// Scan for networks
let networks = nm.list_networks(None).await?;
for net in networks {
println!(
"{} - Signal: {}%, Security: {:?}",
net.ssid,
net.strength.unwrap_or(0),
net.security
);
}
Ok(())
}
Connect to a WPA-PSK protected network:
use nmrs::{NetworkManager, WifiSecurity};
#[tokio::main]
async fn main() -> nmrs::Result<()> {
let nm = NetworkManager::new().await?;
// Connect to a network
nm.connect("MyNetwork", None, WifiSecurity::WpaPsk {
psk: "password123".into()
}).await?;
// Check current connection
if let Some(ssid) = nm.current_ssid().await {
println!("Connected to: {}", ssid);
}
Ok(())
}
All operations return Result<T, ConnectionError> with specific error variants:
use nmrs::{NetworkManager, WifiSecurity, ConnectionError};
#[tokio::main]
async fn main() -> nmrs::Result<()> {
let nm = NetworkManager::new().await?;
match nm.connect("MyNetwork", None, WifiSecurity::WpaPsk {
psk: "wrong_password".into()
}).await {
Ok(_) => println!("Connected successfully"),
Err(ConnectionError::AuthFailed) => eprintln!("Authentication failed - wrong password"),
Err(ConnectionError::NotFound) => eprintln!("Network not found or out of range"),
Err(ConnectionError::Timeout) => eprintln!("Connection timed out"),
Err(e) => eprintln!("Error: {}", e),
}
Ok(())
}
To follow and/or discuss the development of nmrs, you can join the public Discord channel.
|
cosmic-settings by @pop-os |
cosmic-applets by @pop-os |
|
nmrs-tui by @y2w8 |
gaypanel by @pastthepixels |
|
nmrs-gui by @freedesktop-rs |
android-auto by @uglyoldbob |
If something is missing that you'd like to see, please file a PR or issue, adding it to this roadmap.
nm.wifi("wlan0")WifiConnectionBuilder::hiddentry_connect / try_connect_to_bssidconnect() (directed scan for a non-broadcast SSID).ovpn import supportconnect_by_uuid / disconnect_by_uuidnetwork_events() / settings_events() streams and point-in-time snapshot()ConnectionBuilder, add_connection / add_and_activate_connection, and raw zbus accessAdapter1 / Device1Contributions are welcome. Please read CONTRIBUTING.md for guidelines.
Environmental tests are opt-in and ignored by a normal cargo test, so local
test runs never probe the host NetworkManager implicitly. Use
docker compose run --build --rm test-integration for isolated settings,
NetworkManager-routed secrets, native WireGuard activation, and veth-backed
wired DHCP lifecycles, or
test-wifi-integration with two mac80211_hwsim radios for the deterministic
WPA/DHCP and callback-monitor lifecycle. See the contributing guide for the
exact commands.
This project is dual-licensed under either of the following licenses, at your option:
You may use, copy, modify, and distribute this software under the terms of either license.
See the following files for full license texts:
Thank you to everyone who has helped build, test, document, and review nmrs.
(top 30 of 34)
Rust
97.8%
Shell
1.4%