Struct linux_info::network::network_manager::Device
source · pub struct Device { /* private fields */ }Implementations§
source§impl Device
impl Device
sourcepub fn path(&self) -> Result<String, Error>
pub fn path(&self) -> Result<String, Error>
The path of the device as exposed by the udev property ID_PATH.
Note that non-UTF-8 characters are backslash escaped.
Use g_strcompress() to obtain the true (non-UTF-8) string.
sourcepub fn interface(&self) -> Result<String, Error>
pub fn interface(&self) -> Result<String, Error>
The name of the device’s control (and often data) interface. Note that non UTF-8 characters are backslash escaped, so the resulting name may be longer then 15 characters. Use g_strcompress() to revert the escaping.
Examples found in repository?
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104
fn main() {
let dbus = NetworkManager::connect().unwrap();
for device in dbus.devices().unwrap() {
let state = device.state().unwrap();
let kind = device.kind().unwrap();
let interface = device.interface().unwrap();
println!("{:?} {:?} {:?}", interface, kind, state);
if let Ok(apn) = device.modem_apn() {
println!("- has apn {:?}", apn);
}
if matches!(state, DeviceState::Activated) {
let ipv4 = device.ipv4_config().unwrap()
.addresses().unwrap();
println!("- addresses {:?}", ipv4);
}
}
let dbus = ModemManager::connect().unwrap();
for modem in dbus.modems().unwrap() {
println!(
"modem {:?} {:?} {:?}",
modem.model().unwrap(),
modem.manufacturer().unwrap(),
modem.device().unwrap()
);
println!(
"- carrier configuration: {:?}",
modem.carrier_configuration().unwrap()
);
println!(
"- state: {:?}, signal: {:?}",
modem.state().unwrap(),
modem.signal_quality().unwrap()
);
let (allowed_modes, preffered_modes) = modem.current_modes().unwrap();
println!(
"- allowed modes: 2g: {} 3g: {} 4g: {} 5g: {}",
allowed_modes.has_2g(),
allowed_modes.has_3g(),
allowed_modes.has_4g(),
allowed_modes.has_5g()
);
println!(
"- prefered modes: 2g: {} 3g: {} 4g: {} 5g: {}",
preffered_modes.has_2g(),
preffered_modes.has_3g(),
preffered_modes.has_4g(),
preffered_modes.has_5g()
);
println!(
"- bands: {:?}",
modem.current_bands().unwrap()
);
modem.signal_setup(10).unwrap();
thread::sleep(Duration::from_secs(1));
if let Ok(cdma) = modem.signal_cdma() {
println!("- cdma: {:?}", cdma);
}
if let Ok(evdo) = modem.signal_evdo() {
println!("- evdo: {:?}", evdo);
}
if let Ok(gsm) = modem.signal_gsm() {
println!("- gsm: {:?}", gsm);
}
if let Ok(umts) = modem.signal_umts() {
println!("- umts: {:?}", umts);
}
if let Ok(lte) = modem.signal_lte() {
println!("- lte: {:?}", lte);
}
if let Ok(nr5g) = modem.signal_nr5g() {
println!("- nr5g: {:?}", nr5g);
}
}
}sourcepub fn driver(&self) -> Result<String, Error>
pub fn driver(&self) -> Result<String, Error>
The driver handling the device. Non-UTF-8 sequences are backslash escaped. Use g_strcompress() to revert.
sourcepub fn state(&self) -> Result<DeviceState, Error>
pub fn state(&self) -> Result<DeviceState, Error>
The current state of the device.
Examples found in repository?
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104
fn main() {
let dbus = NetworkManager::connect().unwrap();
for device in dbus.devices().unwrap() {
let state = device.state().unwrap();
let kind = device.kind().unwrap();
let interface = device.interface().unwrap();
println!("{:?} {:?} {:?}", interface, kind, state);
if let Ok(apn) = device.modem_apn() {
println!("- has apn {:?}", apn);
}
if matches!(state, DeviceState::Activated) {
let ipv4 = device.ipv4_config().unwrap()
.addresses().unwrap();
println!("- addresses {:?}", ipv4);
}
}
let dbus = ModemManager::connect().unwrap();
for modem in dbus.modems().unwrap() {
println!(
"modem {:?} {:?} {:?}",
modem.model().unwrap(),
modem.manufacturer().unwrap(),
modem.device().unwrap()
);
println!(
"- carrier configuration: {:?}",
modem.carrier_configuration().unwrap()
);
println!(
"- state: {:?}, signal: {:?}",
modem.state().unwrap(),
modem.signal_quality().unwrap()
);
let (allowed_modes, preffered_modes) = modem.current_modes().unwrap();
println!(
"- allowed modes: 2g: {} 3g: {} 4g: {} 5g: {}",
allowed_modes.has_2g(),
allowed_modes.has_3g(),
allowed_modes.has_4g(),
allowed_modes.has_5g()
);
println!(
"- prefered modes: 2g: {} 3g: {} 4g: {} 5g: {}",
preffered_modes.has_2g(),
preffered_modes.has_3g(),
preffered_modes.has_4g(),
preffered_modes.has_5g()
);
println!(
"- bands: {:?}",
modem.current_bands().unwrap()
);
modem.signal_setup(10).unwrap();
thread::sleep(Duration::from_secs(1));
if let Ok(cdma) = modem.signal_cdma() {
println!("- cdma: {:?}", cdma);
}
if let Ok(evdo) = modem.signal_evdo() {
println!("- evdo: {:?}", evdo);
}
if let Ok(gsm) = modem.signal_gsm() {
println!("- gsm: {:?}", gsm);
}
if let Ok(umts) = modem.signal_umts() {
println!("- umts: {:?}", umts);
}
if let Ok(lte) = modem.signal_lte() {
println!("- lte: {:?}", lte);
}
if let Ok(nr5g) = modem.signal_nr5g() {
println!("- nr5g: {:?}", nr5g);
}
}
}sourcepub fn kind(&self) -> Result<DeviceKind, Error>
pub fn kind(&self) -> Result<DeviceKind, Error>
The general type of the network device; ie Ethernet, Wi-Fi, etc.
Examples found in repository?
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104
fn main() {
let dbus = NetworkManager::connect().unwrap();
for device in dbus.devices().unwrap() {
let state = device.state().unwrap();
let kind = device.kind().unwrap();
let interface = device.interface().unwrap();
println!("{:?} {:?} {:?}", interface, kind, state);
if let Ok(apn) = device.modem_apn() {
println!("- has apn {:?}", apn);
}
if matches!(state, DeviceState::Activated) {
let ipv4 = device.ipv4_config().unwrap()
.addresses().unwrap();
println!("- addresses {:?}", ipv4);
}
}
let dbus = ModemManager::connect().unwrap();
for modem in dbus.modems().unwrap() {
println!(
"modem {:?} {:?} {:?}",
modem.model().unwrap(),
modem.manufacturer().unwrap(),
modem.device().unwrap()
);
println!(
"- carrier configuration: {:?}",
modem.carrier_configuration().unwrap()
);
println!(
"- state: {:?}, signal: {:?}",
modem.state().unwrap(),
modem.signal_quality().unwrap()
);
let (allowed_modes, preffered_modes) = modem.current_modes().unwrap();
println!(
"- allowed modes: 2g: {} 3g: {} 4g: {} 5g: {}",
allowed_modes.has_2g(),
allowed_modes.has_3g(),
allowed_modes.has_4g(),
allowed_modes.has_5g()
);
println!(
"- prefered modes: 2g: {} 3g: {} 4g: {} 5g: {}",
preffered_modes.has_2g(),
preffered_modes.has_3g(),
preffered_modes.has_4g(),
preffered_modes.has_5g()
);
println!(
"- bands: {:?}",
modem.current_bands().unwrap()
);
modem.signal_setup(10).unwrap();
thread::sleep(Duration::from_secs(1));
if let Ok(cdma) = modem.signal_cdma() {
println!("- cdma: {:?}", cdma);
}
if let Ok(evdo) = modem.signal_evdo() {
println!("- evdo: {:?}", evdo);
}
if let Ok(gsm) = modem.signal_gsm() {
println!("- gsm: {:?}", gsm);
}
if let Ok(umts) = modem.signal_umts() {
println!("- umts: {:?}", umts);
}
if let Ok(lte) = modem.signal_lte() {
println!("- lte: {:?}", lte);
}
if let Ok(nr5g) = modem.signal_nr5g() {
println!("- nr5g: {:?}", nr5g);
}
}
}sourcepub fn ipv4_config(&self) -> Result<Ipv4Config, Error>
pub fn ipv4_config(&self) -> Result<Ipv4Config, Error>
Ipv4 Configuration of the device. Only valid when the device is in DeviceState::Activated
Examples found in repository?
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104
fn main() {
let dbus = NetworkManager::connect().unwrap();
for device in dbus.devices().unwrap() {
let state = device.state().unwrap();
let kind = device.kind().unwrap();
let interface = device.interface().unwrap();
println!("{:?} {:?} {:?}", interface, kind, state);
if let Ok(apn) = device.modem_apn() {
println!("- has apn {:?}", apn);
}
if matches!(state, DeviceState::Activated) {
let ipv4 = device.ipv4_config().unwrap()
.addresses().unwrap();
println!("- addresses {:?}", ipv4);
}
}
let dbus = ModemManager::connect().unwrap();
for modem in dbus.modems().unwrap() {
println!(
"modem {:?} {:?} {:?}",
modem.model().unwrap(),
modem.manufacturer().unwrap(),
modem.device().unwrap()
);
println!(
"- carrier configuration: {:?}",
modem.carrier_configuration().unwrap()
);
println!(
"- state: {:?}, signal: {:?}",
modem.state().unwrap(),
modem.signal_quality().unwrap()
);
let (allowed_modes, preffered_modes) = modem.current_modes().unwrap();
println!(
"- allowed modes: 2g: {} 3g: {} 4g: {} 5g: {}",
allowed_modes.has_2g(),
allowed_modes.has_3g(),
allowed_modes.has_4g(),
allowed_modes.has_5g()
);
println!(
"- prefered modes: 2g: {} 3g: {} 4g: {} 5g: {}",
preffered_modes.has_2g(),
preffered_modes.has_3g(),
preffered_modes.has_4g(),
preffered_modes.has_5g()
);
println!(
"- bands: {:?}",
modem.current_bands().unwrap()
);
modem.signal_setup(10).unwrap();
thread::sleep(Duration::from_secs(1));
if let Ok(cdma) = modem.signal_cdma() {
println!("- cdma: {:?}", cdma);
}
if let Ok(evdo) = modem.signal_evdo() {
println!("- evdo: {:?}", evdo);
}
if let Ok(gsm) = modem.signal_gsm() {
println!("- gsm: {:?}", gsm);
}
if let Ok(umts) = modem.signal_umts() {
println!("- umts: {:?}", umts);
}
if let Ok(lte) = modem.signal_lte() {
println!("- lte: {:?}", lte);
}
if let Ok(nr5g) = modem.signal_nr5g() {
println!("- nr5g: {:?}", nr5g);
}
}
}sourcepub fn modem_apn(&self) -> Result<String, Error>
pub fn modem_apn(&self) -> Result<String, Error>
The access point name the modem is connected to. Blank if disconnected.
Examples found in repository?
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104
fn main() {
let dbus = NetworkManager::connect().unwrap();
for device in dbus.devices().unwrap() {
let state = device.state().unwrap();
let kind = device.kind().unwrap();
let interface = device.interface().unwrap();
println!("{:?} {:?} {:?}", interface, kind, state);
if let Ok(apn) = device.modem_apn() {
println!("- has apn {:?}", apn);
}
if matches!(state, DeviceState::Activated) {
let ipv4 = device.ipv4_config().unwrap()
.addresses().unwrap();
println!("- addresses {:?}", ipv4);
}
}
let dbus = ModemManager::connect().unwrap();
for modem in dbus.modems().unwrap() {
println!(
"modem {:?} {:?} {:?}",
modem.model().unwrap(),
modem.manufacturer().unwrap(),
modem.device().unwrap()
);
println!(
"- carrier configuration: {:?}",
modem.carrier_configuration().unwrap()
);
println!(
"- state: {:?}, signal: {:?}",
modem.state().unwrap(),
modem.signal_quality().unwrap()
);
let (allowed_modes, preffered_modes) = modem.current_modes().unwrap();
println!(
"- allowed modes: 2g: {} 3g: {} 4g: {} 5g: {}",
allowed_modes.has_2g(),
allowed_modes.has_3g(),
allowed_modes.has_4g(),
allowed_modes.has_5g()
);
println!(
"- prefered modes: 2g: {} 3g: {} 4g: {} 5g: {}",
preffered_modes.has_2g(),
preffered_modes.has_3g(),
preffered_modes.has_4g(),
preffered_modes.has_5g()
);
println!(
"- bands: {:?}",
modem.current_bands().unwrap()
);
modem.signal_setup(10).unwrap();
thread::sleep(Duration::from_secs(1));
if let Ok(cdma) = modem.signal_cdma() {
println!("- cdma: {:?}", cdma);
}
if let Ok(evdo) = modem.signal_evdo() {
println!("- evdo: {:?}", evdo);
}
if let Ok(gsm) = modem.signal_gsm() {
println!("- gsm: {:?}", gsm);
}
if let Ok(umts) = modem.signal_umts() {
println!("- umts: {:?}", umts);
}
if let Ok(lte) = modem.signal_lte() {
println!("- lte: {:?}", lte);
}
if let Ok(nr5g) = modem.signal_nr5g() {
println!("- nr5g: {:?}", nr5g);
}
}
}