Skip to content

Commit

Permalink
fix: wifiscanner parse networks
Browse files Browse the repository at this point in the history
  • Loading branch information
chlebon committed Nov 29, 2024
1 parent de1b5c6 commit 0c2f961
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 14 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 14 additions & 13 deletions libs/wifiscanner/src/sys/macos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,20 +43,21 @@ fn parse_system_profile(network_list: &str) -> Result<Vec<Wifi>> {
let re = Regex::new(r"(?m)^\s+([^\n]+):\n\s+PHY Mode: [^\n]+\n\s+Channel: ([^\n]+)\n\s+.*?\n\s+Security: ([^\n]+)\n\s+Signal / Noise: ([^\n]+)")
.unwrap();
for w in re.captures_iter(network_list) {

let ssid = w[1].trim().to_string();
let channel = w[2].split('(').next().unwrap().trim().to_string();
let security = w[3].trim().to_string();
let signal = w[4].split('/').next().unwrap().trim().to_string();

let wifi = Wifi{
ssid,
channel,
signal_level: signal.split(' ').next().unwrap().trim().to_string(),
security,
mac: String::new(),
};
wifis.push(wifi);
if !ssid.contains("Other Local Wi-Fi Networks") {
let channel = w[2].split('(').next().unwrap().trim().to_string();
let security = w[3].trim().to_string();
let signal = w[4].split('/').next().unwrap().trim().to_string();

let wifi = Wifi {
ssid,
channel,
signal_level: signal.split(' ').next().unwrap().trim().to_string(),
security,
mac: String::new(),
};
wifis.push(wifi);
}
}

Ok(wifis)
Expand Down

0 comments on commit 0c2f961

Please sign in to comment.