pub struct NetworkManager<'a> { /* private fields */ }
Implementations§
Source§impl<'a> NetworkManager<'a>
impl<'a> NetworkManager<'a>
Sourcepub fn new(dbus_connection: &'a Connection) -> Self
pub fn new(dbus_connection: &'a Connection) -> Self
Examples found in repository?
examples/testing.rs (line 9)
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 // NetworkManager >= 1.24
42 // println!("Hardware Address: {:?}", Any::hw_address(&x)?);
43
44 // NetworkManager < 1.24
45 // println!("Hardware Address: {:?}", Wired::hw_address(&x)?);
46
47 println!("Speed: {:?}", x.speed()?);
48 }
49 _ => {}
50 }
51
52 Ok(())
53}
Sourcepub fn reload(&self, flags: ReloadFlag) -> Result<(), Error>
pub fn reload(&self, flags: ReloadFlag) -> Result<(), Error>
Reloads NetworkManager by the given scope
Sourcepub fn get_devices(&self) -> Result<Vec<Device<'_>>, Error>
pub fn get_devices(&self) -> Result<Vec<Device<'_>>, Error>
Returns only realized network devices
Examples found in repository?
examples/testing.rs (line 11)
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 // NetworkManager >= 1.24
42 // println!("Hardware Address: {:?}", Any::hw_address(&x)?);
43
44 // NetworkManager < 1.24
45 // println!("Hardware Address: {:?}", Wired::hw_address(&x)?);
46
47 println!("Speed: {:?}", x.speed()?);
48 }
49 _ => {}
50 }
51
52 Ok(())
53}
Sourcepub fn get_all_devices(&self) -> Result<Vec<Device<'_>>, Error>
pub fn get_all_devices(&self) -> Result<Vec<Device<'_>>, Error>
Returns all the network devices
Sourcepub fn get_device_by_ip_iface(&self, iface: &str) -> Result<Device<'_>, Error>
pub fn get_device_by_ip_iface(&self, iface: &str) -> Result<Device<'_>, Error>
Examples found in repository?
examples/testing.rs (line 38)
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 // NetworkManager >= 1.24
42 // println!("Hardware Address: {:?}", Any::hw_address(&x)?);
43
44 // NetworkManager < 1.24
45 // println!("Hardware Address: {:?}", Wired::hw_address(&x)?);
46
47 println!("Speed: {:?}", x.speed()?);
48 }
49 _ => {}
50 }
51
52 Ok(())
53}
pub fn networking_enabled(&self) -> Result<bool, Error>
pub fn wireless_enabled(&self) -> Result<bool, Error>
pub fn wireless_hardware_enabled(&self) -> Result<bool, Error>
Auto Trait Implementations§
impl<'a> Freeze for NetworkManager<'a>
impl<'a> !RefUnwindSafe for NetworkManager<'a>
impl<'a> !Send for NetworkManager<'a>
impl<'a> !Sync for NetworkManager<'a>
impl<'a> Unpin for NetworkManager<'a>
impl<'a> !UnwindSafe for NetworkManager<'a>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more