Git Product home page Git Product logo

nl80211's Introduction

Crates.io Coverage Status Build Status License: MIT contributions welcome

nl80211

API documentation

This crate aims to provide a low level access to nl80211.

This crate is inspired by the go wifi package made by @mdlayher.

⚠️ This library only works on Linux.

⚠️ This crate is a work in progress

Built-in functions

This crate has some built-in functions to fetch information and metrics of wifi interfaces and wireless networks.

Get interface information

extern crate nl80211;

use std::error::Error;
use nl80211::Socket;

fn main() -> Result<(), Box<dyn Error>> {
  let interfaces = Socket::connect()?.get_interfaces_info()?;
  for interface in interfaces {
      let station = interface.get_station_info();
      println!("{}", station?.pretty_format());

      // bssid : FF:FF:FF:FF:FF:FF
      // connected time : 35.816666 minutes
      // beacon loss : 0
      // signal : -60 dBm
      // average signal : -61 dBm
      // rx packets : 148983
      // tx packets : 46335
      // rx bitrate : 60 Mb/s
      // tx bitrate : 140 Mb/s
      // tx retries : 12578
      // tx failed : 2
  }

  Ok(())
}

use nl80211::Socket;

fn main() -> Result<(), neli::err::NlError> {
  let interfaces = Socket::connect()?.get_interfaces_info()?;

  for interface in interfaces {
      println!("{}", interface);

      // Interface {
      //   index: Some([3, 0, 0, 0]),
      //   ssid: Some([101, 100, 117, 114, 111, 97, 109]),
      //   mac: Some([255, 255, 255, 255, 255, 255]),
      //   name: Some([119, 108, 112, 53, 115, 48]),
      //   frequency: Some([108, 9, 0, 0]),
      //   channel: Some([1, 0, 0, 0]),
      //   power: Some([164, 6, 0, 0]),
      //   phy: Some([0, 0, 0, 0]),
      //   device: Some([1, 0, 0, 0, 0, 0, 0, 0])
      // }

      println!("{}", interface);

      // essid : eduroam
      // mac : FF:FF:FF:FF:FF:FF
      // interface : wlp5s0
      // frequency : 2.412 Ghz
      // channel : 1
      // power : 17 dBm
      // phy : 0
      // device : 1
    }

    Ok(())
}

Get Access Point information and metrics

extern crate nl80211;

use std::error::Error;
use nl80211::Socket;

fn main() -> Result<(), Box<dyn Error>> {
  let interfaces = Socket::connect()?.get_interfaces_info()?;
  for interface in interfaces {
      let station = interface.get_station_info();
      println!("{}", station?);

      // bssid : FF:FF:FF:FF:FF:FF
      // connected time : 35.816666 minutes
      // beacon loss : 0
      // signal : -60 dBm
      // average signal : -61 dBm
      // rx packets : 148983
      // tx packets : 46335
      // rx bitrate : 60 Mb/s
      // tx bitrate : 140 Mb/s
      // tx retries : 12578
      // tx failed : 2
  }

  Ok(())
}

Todo

  • Implement custom errors
  • Add more built-in functions
  • Improve documentation

nl80211's People

Contributors

eonm avatar mvertescher avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

nl80211's Issues

Maybe impl `std::fmt::Display`

It's a little strange that types in this repo implement a custom printing trait PrettyFormat. The Display trait is typically used in this situation.

Perhaps we can migrate PrettyFormat impls to std::fmt::Display. This would ease usage, for example:

// This
println!("{}", interface);

// Instead of below
// println!("{}\n", interface.pretty_format());

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.