GithubHelp home page GithubHelp logo

elefantti / wifi-scan Goto Github PK

View Code? Open in Web Editor NEW

This project forked from bmegli/wifi-scan

0.0 0.0 0.0 71 KB

A nl80211 C/C++ library for monitoring signal strength of WiFi networks

License: Mozilla Public License 2.0

C 96.77% Makefile 2.08% CMake 1.14%

wifi-scan's Introduction

wifi-scan

This is a small C/C++ library for monitoring signal strength of WiFi networks. It can collect data from:

  • associated station only (rapidly)
  • all networks around (slow passive scan)

Platforms

Any platforms supporting nl80211 netlink interface (new 802.11 interface). Generally *nix platforms.

Hardware

Wireless devices that have cfg80211/mac80211 driver. Currently all new Linux wireless drivers should be written targeting either cfg80211 for fullmac devices or mac80211 for softmac devices.

State

The return values of public library functions are subject to change (mainly error codes). Currently if anything goes wrong library dies cleanly with error message on stderr explaining what happened. Note that if library dies - it also kills your program and you have no chance to recover.

Dependencies

The library depends on libmnl for netlink nl80211 user space - kernel space communication.

Building Instructions

# update package repositories
sudo apt-get update 
# get compilers and make
sudo apt-get install build-essential
# get dependencies
sudo apt-get install libmnl0 libmnl-dev
# get git
sudo apt-get install git
# clone the repository
git clone https://github.com/elefAntti/wifi-scan.git

# finally build the library and examples
cd wifi-scan
make all

Testing

Check your wireless interface name with ifconfig:

ifconfig

Run wifi-scan-station with your interface, e.g. wlan0

./wifi-scan-station wlan0

Run wifi-scan-all with your interface, e.g. wlan0.

Triggering a scan needs permission so:

sudo ./wifi-scan-all wlan0

Using

See examples directory for more complete and commented examples with error handling.

Normally you would call wifi_scan_station or wifi_scan_all in a loop.

wifi-scan-station

	struct station_info station;
	struct wifi_scan *wifi = wifi_scan_init("wlan0");
	
	if (wifi_scan_station(wifi, &station) > 0 )
		printf("%s signal %d dBm %u rx %u tx\n",
		station.ssid,  station.signal_dbm,
		station.rx_packets, station.tx_packets);
	
	wifi_scan_close(wifi);

wifi-scan-all

	int status, i;
	struct bss_info bss[10]; 
	struct wifi_scan *wifi = wifi_scan_init("wlan0");

	status=wifi_scan_all(wifi, bss, 10);
		
	for(i=0;i<status && i<10;++i)	
		printf("%s signal %d dBm on %u MHz seen %d ms ago status %s\n",
		bss[i].ssid,  bss[i].signal_mbm/100, bss[i].frequency, bss[i].seen_ms_ago,
		(bss[i].status==BSS_ASSOCIATED ? "associated" : ""));

	wifi_scan_close(wifi);

Compiling your code

Don't forget to link with lmnl

C

gcc wifi_scan.c your_program.c -lmnl -o your-program

C++

gcc -c wifi_scan.c
g++ -c your_program.cpp
g++ wifi_scan.o your_program.o -lmnl -o your-program

Understanding nl80211 Netlink

Here are some of the resources that helped writing this library:

And finally the implementation wifi-scan.c has some comments that may be usefull to you.

License

Library is licensed under Mozilla Public License, v. 2.0

This is similiar to LGPL but more permissive:

  • you can use it as LGPL in prioprietrary software
  • unlike LGPL you may compile it statically with your code

Like in LGPL, if you modify this library, you have to make your changes available. Making a github fork of the library with your changes satisfies those requirements perfectly.

Additional information

Building with CMake

Alternatively build examples and shared library with Cmake

sudo apt-get install cmake
cd wifi-scan
mkdir build
cd build
cmake ..
make

wifi-scan's People

Contributors

bmegli avatar anttivnavitec avatar fzirker avatar elefantti avatar

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.