rs-wifi

Crates.iors-wifi
lib.rsrs-wifi
version0.1.8
created_at2025-04-17 15:35:41.220673+00
updated_at2025-05-15 03:04:58.094254+00
description`rswifi` is cross-platform wireless network (WiFi) management.
homepagehttps://github.com/jesses2025smith/rs-wifi
repositoryhttps://github.com/jesses2025smith/rs-wifi
max_upload_size
id1638015
size73,343
Jesse Smith (jesses2025smith)

documentation

README

rswifi

Cross-platform wireless network (WiFi) management

Features

  • Scan for available WiFi networks
  • Connect to a WiFi network
  • Disconnect from a WiFi network
  • Retrieve connection status
  • Cross-platform support (Windows, Linux)

Installation

To use rswifi, add it to your Cargo.toml:

[dependencies]
rs-wifi = "0.1"

Usage

Here is a basic example:

use rswifi::{AkmType, AuthAlg, CipherType, Error, IFaceStatus, Profile, Result, WiFiInterface as _, WifiUtil};

fn main() -> Result<()> {
    let util = WifiUtil::new()?;
    let ifaces = util.interfaces()?;
    let iface = ifaces.first()
        .ok_or(Error::Other("No iface found".into()))?;

    // Disconnect
    iface.disconnect()?;
    std::thread::sleep(std::time::Duration::from_millis(100));
    let status = iface.status()?;
    assert_eq!(status, IFaceStatus::Disconnected);

    // Add Profle
    let ssid = "TestSSID";
    let key = "12345678";
    let mut profile = Profile::new(ssid)
        .with_key(Some(key.into()))
        .with_auth(AuthAlg::Open)
        .with_cipher(CipherType::Ccmp);
    profile.add_akm(AkmType::Wpa2Psk);
    iface.add_network_profile(&profile)?;

    // Scan
    iface.scan()?;
    std::thread::sleep(std::time::Duration::from_secs(5));
    let results = iface.scan_results()?;
    for result in results {
        if result.ssid() == ssid {
            println!("Scanned ssid: {}", ssid);
        }
    }

    // Connect
    let ret = iface.connect(ssid)?;
    assert!(ret);
    std::thread::sleep(std::time::Duration::from_millis(500));
    let status = iface.status()?;
    assert_eq!(status, IFaceStatus::Connected);

    // Remove Profile
    iface.remove_network_profile(&ssid)?;

    // Get Profile names
    let results = iface.network_profile_name_list()?;
    println!("{:?}", results);

    Ok(())
}

License

This project is licensed under the MIT License. See the LICENSE file for details.

Commit count: 29

cargo fmt