Initial committ
also added first utils for nmcli device wifi list
This commit is contained in:
commit
8515fe521e
4 changed files with 74 additions and 0 deletions
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
/target
|
||||||
16
Cargo.lock
generated
Normal file
16
Cargo.lock
generated
Normal file
|
|
@ -0,0 +1,16 @@
|
||||||
|
# This file is automatically @generated by Cargo.
|
||||||
|
# It is not intended for manual editing.
|
||||||
|
version = 3
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "anyhow"
|
||||||
|
version = "1.0.71"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "9c7d0618f0e0b7e8ff11427422b64564d5fb0be1940354bfe2e0529b18a9d9b8"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "wifi-connector"
|
||||||
|
version = "0.1.0"
|
||||||
|
dependencies = [
|
||||||
|
"anyhow",
|
||||||
|
]
|
||||||
9
Cargo.toml
Normal file
9
Cargo.toml
Normal file
|
|
@ -0,0 +1,9 @@
|
||||||
|
[package]
|
||||||
|
name = "wifi-connector"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2021"
|
||||||
|
|
||||||
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
anyhow = "1.0.71"
|
||||||
48
src/main.rs
Normal file
48
src/main.rs
Normal file
|
|
@ -0,0 +1,48 @@
|
||||||
|
use std::{process::Command, vec};
|
||||||
|
use anyhow::*;
|
||||||
|
|
||||||
|
struct Network {
|
||||||
|
in_use: bool,
|
||||||
|
ssid: String,
|
||||||
|
signal: u8,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Network {
|
||||||
|
fn from_nmcli_stdout(line: String) {
|
||||||
|
for element in line.split(' ') {
|
||||||
|
println!("{}", element);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn get_available_wifis() -> Result<String> {
|
||||||
|
let output = Command::new("nmcli")
|
||||||
|
.arg("device")
|
||||||
|
.arg("wifi")
|
||||||
|
.arg("list")
|
||||||
|
.output()
|
||||||
|
.expect("Failed to execute command");
|
||||||
|
|
||||||
|
Ok(String::from_utf8_lossy(output.stdout.as_slice()).into())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn get_descriptor_positions(header_line: &String) -> Vec<u8> {
|
||||||
|
let mut positions: Vec<u8> = vec![];
|
||||||
|
|
||||||
|
positions.push(0);
|
||||||
|
positions.push(header_line.find(" SSID").expect("SSID not found in header string") as u8 +1);
|
||||||
|
positions.push(header_line.find("SIGNAL").expect("SIGNAL not found in header string") as u8);
|
||||||
|
|
||||||
|
return positions;
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let all_wifis: String = get_available_wifis().expect("Wifi fetching exploded");
|
||||||
|
let positions = get_descriptor_positions(&all_wifis);
|
||||||
|
for position in (positions) {
|
||||||
|
println!("{}", position);
|
||||||
|
}
|
||||||
|
// for line in all_wifis.split("\n") {
|
||||||
|
// Network::from_nmcli_stdout(line.to_owned());
|
||||||
|
// }
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue