commit 8515fe521e9ad63d1ab7355c612e8534929cdfbb Author: s-prechtl Date: Tue Jun 13 00:19:37 2023 +0200 Initial committ also added first utils for nmcli device wifi list diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ea8c4bf --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/target diff --git a/Cargo.lock b/Cargo.lock new file mode 100644 index 0000000..2670759 --- /dev/null +++ b/Cargo.lock @@ -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", +] diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..7bf03fa --- /dev/null +++ b/Cargo.toml @@ -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" diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 0000000..e8fad5c --- /dev/null +++ b/src/main.rs @@ -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 { + 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 { + let mut positions: Vec = 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()); + // } +}