librefi_rs/src/main.rs

48 lines
1.1 KiB
Rust
Raw Normal View History

2021-12-26 13:55:29 +01:00
#[macro_use]
extern crate lazy_static;
mod connection_check;
mod connectors;
2022-01-07 20:28:09 +01:00
use crate::connectors::types::{Connects, ListsNetworkInterfaces, ListsNetworks};
2021-12-26 13:55:29 +01:00
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// let ip4 = connection_check::ipv4_info().await?;
// println!("{:?}", ip4);
2022-01-07 20:28:09 +01:00
let connector = connectors::networkmanager::NetworkManagerConnector {};
2021-12-26 13:55:29 +01:00
2022-01-07 20:28:09 +01:00
let ifaces = connector
.list_network_interfaces()
.expect("network interface listing errored");
2021-12-26 13:55:29 +01:00
for iface in &ifaces {
2021-12-26 13:55:29 +01:00
println!("{:?}", iface);
}
2022-01-07 20:28:09 +01:00
let iface = ifaces
.into_iter()
.find(|f| f.machine_name == "wlp2s0")
.expect("Wi-Fi interface not found");
2022-01-07 20:28:09 +01:00
let networks = connector
.list_networks(&iface)
.expect("network listing errored");
2021-12-26 13:55:29 +01:00
for net in &networks {
2021-12-26 13:55:29 +01:00
println!("{:?}", net);
}
2022-01-07 20:28:09 +01:00
/*
let network = networks
.into_iter()
.find(|net| net.ssid == "test")
.expect("network not found");
2022-01-07 20:28:09 +01:00
connector
.connect_to_network(&iface, &network, None)
.expect("could not connect to network");
*/
2021-12-26 13:55:29 +01:00
Ok(())
}