Giter VIP home page Giter VIP logo

node-wireless's Introduction

node-wireless

A utility for handling interactions with wireless interfaces on *nix distributions.

Goals

This Node.js module will eventually provide all of the following features:

  • Get a list of visible networks ✓
  • Display info about connected network ✓
  • Display different information about other networks, e.g. strength ✓
  • Disconnect from network ✓
  • Connect to open networks ✓
  • Connect to secure networks, providing credentials or certificate
  • Trigger an event when a new network appears ✓
  • Trigger an event when a network changes ✓
  • Trigger an event when a network disappears or lose connection ✓

Basically, this class should be able to do anything a user would be able to do using their OS's network configuration tools.

Currently there is a dependency on the tool wpa_supplicant being installed. This module actually executes that utility many times to get results. Eventually we'll move to a D-Bus based approach (#19) which will result in much quicker results and fewer dependencies.

Installation

npm install wireless

Usage

var wireless = new Wireless({
    iface: 'wlan0',
	updateFrequency: 10, // Optional, seconds to scan for networks
	connectionSpyFrequency: 2, // Optional, seconds to scan if connected
	vanishThreshold: 2 // Optional, how many scans before network considered gone
});

wireless.enable(function(err) {
	wireless.start();
});

Events

  • appear: A never-before seen network has appeared
  • change: A seen wireless network has changed properties (e.g. SSID or encryption)
  • signal: A seen wireless network has it's signal change (e.g. strength or quality)
  • vanish: A seen network has been determined to no longer be accessible
  • empty: A network scan was executed but nothing was discovered
  • error: Something bad has happened
  • command: Debugging: Emits the shell command about to be executed
  • batch: Debugging: Raw information about all networks from the last batch scan
  • join: The interface has connected to a new network
  • former: The interface had been connected to a network before Wireless ran
  • dhcp: An IP address has been assigned via DHCP
  • leave: The interface has left the network it was connected to
  • stop: The interface is no longer looking for networks

Methods

  • Constructor(config): Creates a new Wireless instance
  • enable(cb): Enables the wireless interface
  • start(): Begins the scanning
  • join(network, pwd, cb): Attempts to join the specified network
  • dhcp(cb): Attempts to enable DHCP for the interface and get an IP Address
  • dhcpStop(cb): Attempts to stop the DHCP process
  • leave(cb): Attempts to leave the specified network
  • stop(cb): Stops the scanning process
  • disable(cb): Disables the wireless interface
  • list(): Gets a list of all the currently visible networks

Current Status

Currently, enabling/disabling adapter works, finding new networks will trigger events, able to read encryption method and other data, and disappearing networks trigger events, able to enable and disable dhcp, able to connect to unsecure networks.

$ ./examples/scan-connect-disconnect.js wlan0
[PROGRESS] Enabling wireless card...
[PROGRESS] Wireless card enabled.
[PROGRESS] Starting wireless scan...
[PROGRESS] Wireless scanning has commenced.
[  APPEAR] Zen Buddhist Temple Public [00:27:22:14:DB:84] 64% -65 dBm NONE
[  APPEAR] ArborMesh-ch1 [0A:B3:85:5F:45:99] 62% -66 dBm NONE
[  APPEAR] AHOPS [00:23:A2:DE:4A:B0] 100% -14 dBm WPA&WPA2
[  APPEAR] ArborMesh [62:3D:28:71:4F:79] 100% -28 dBm NONE
[  APPEAR] dOpsInternal [00:0C:41:36:A3:F6] 100% -25 dBm WPA
[  APPEAR] Zen Buddhist Temple Public [F8:D1:11:47:EE:4A] 100% -17 dBm NONE
[  APPEAR] Zen Buddhist Temple Private [FA:D1:11:47:EE:4B] 100% -28 dBm WPA2
[  APPEAR] Zen Buddhist Temple Public [F8:D1:11:54:A9:DE] 100% -23 dBm NONE
[  APPEAR] Zen Buddhist Temple Private [FA:D1:11:54:A9:DF] 91% -46 dBm WPA2
[  APPEAR] ATT200 [CC:7D:37:81:0F:20] 68% -62 dBm WPA&WPA2
Yay, we connected! I will try to get an IP.
[    JOIN] Zen Buddhist Temple Public [00:27:22:14:DB:84] 
[    DHCP] Leased IP 10.88.0.58
Yay, I got an IP address (10.88.0.58)! I'm going to disconnect in 20 seconds.
[  LEVELS] Zen Buddhist Temple Public
[  LEVELS] ArborMesh-ch1
[  LEVELS] AHOPS
[  LEVELS] ArborMesh
[  LEVELS] dOpsInternal
[  LEVELS] Zen Buddhist Temple Public
[  LEVELS] Zen Buddhist Temple Private
[  LEVELS] Zen Buddhist Temple Public
[  LEVELS] ATT200
20 seconds are up! Attempting to turn off DHCP...
DHCP has been turned off. Leaving the network...
[   LEAVE] Left the network
[  LEVELS] Zen Buddhist Temple Public
[  LEVELS] ArborMesh-ch1
[  LEVELS] AHOPS
[  LEVELS] ArborMesh
[  LEVELS] dOpsInternal
[  LEVELS] Zen Buddhist Temple Public
[  LEVELS] Zen Buddhist Temple Public
[  APPEAR] Zen Buddhist Temple Private [02:27:22:14:DB:85] 100% -20 dBm WPA2
[  LEVELS] Zen Buddhist Temple Private
[  APPEAR] 2WIRE163 [00:1F:B3:6B:97:D9] 75% -57 dBm WEP
^C[PROGRESS] Gracefully shutting down from SIGINT (Ctrl+C)
[PROGRESS] Disabling Adapter...
[PROGRESS] Stopping Wireless App...
[PROGRESS] Exiting...

Requirements

Needs wpa_supplicant, a wireless card which can see a list of available networks.

Assumptions

  • We assume that DHCP isn't enabled on the wireless device by default.
  • I've only tried this on Arch and Debian Linux.
  • I've only tried this using a wireless card with the RTL8187 and rt2800usb chipsets.

License

Dual MIT/GPL

node-wireless's People

Contributors

scharc avatar stevepacker avatar tlhunter avatar

Stargazers

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

Watchers

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

node-wireless's Issues

underscore

Add underscore as a dependency in the package.json

Make the repo no longer stupid

This was my first node module IIRC. It's laid out stupidly.

The root of the github project should be the module, no dependencies should be committed, a simple sample app should exist in a sub directory and be documented in the readme.

Network list iterable

Make it so that _.each() works with the list of networks. I think we'll need a normal array instead of an object where the keys are the mac addresses.

-100 dBm breaks regex

sometimes I scan and the quality line is (something like)
Quality=10/70 Signal level=-100 dBm

and the regex for signal level is
-?[0-9]{1,2} dBm

but it should be
-?[0-9]{1,3} dBm

to handle 3 digits

Network Encryption Type

Determine if an encrypted network is either a WPA or a WEP encrypted network. Currently we only know if it is encrypted or not.

The reason we need to know what kind of encryption it is is due to the different types of commands required to connect to the two networks.

# Connect to a WEP network
iwconfig INTERFACE essid "ESSID" key s:KEY

# Connect to a WPA network
wpa_passphrase myrouter mypassphrase > wpa.conf
wpa_supplicant -Dwext -iINTERFACE -cwpa.conf

Tweak Change Event Triggers

Need to fine-tune the requirements which trigger a network change event. Should it just be certain things that trigger it? Should a major change in signal strength cause a change event? Or, should there be a different event for signal strength changes?

License

Thomas--this is a great package. Do you have a license you can add to it (e.g. MIT, etc)?

Parsing Quality line variability

In the Quality line, I've seen a couple of different formats, both which break the regex parser in Wireless.prototype._parseScan (the first line breaks because it's a 3-digit number):

Quality=100/100  Signal level=47/100
Quality=66/100  Signal level=52/100
Quality=58/100  Signal level=80/100
Quality=61/100  Signal level=72/100
Quality:23  Signal level:0  Noise level:0
Quality:93  Signal level:0  Noise level:0
Quality:13  Signal level:0  Noise level:0

This was seen on Raspbian (Raspberry Pi):

  • iwconfig: Wireless-Tools version 30
  • iw: version 3.4
  • /etc/debian_version: 7.6
  • uname -r: 3.12.28+
  • uname -m: armv6l

Trigger Disconnect Event

Trigger an event when we disconnect from a network. Possibly send the details of the network we just disconnected from as well.

Network Disappear Event

Fire an event when a network disappears.

This isn't as easy as it sounds; we need to have a threshold. E.g., does a network disappear as soon as it isn't available in a listing, or does it actually disappear when it's been missing for a few scans. This threshold should be configurable.

Uncaught errors when killing child process

Hitting Ctrl+C can sometimes cause uncaught errors to be throw. We should instead catch and emit.

[   FATAL] Got some major errors from our scan command:Error: Command failed:    

/home/tlhunter/Projects/node-wireless-test/node_modules/wireless/index.js:337    
            throw err;                                                           
                  ^                                                              
Error: Command failed:                                                           
    at ChildProcess.exithandler (child_process.js:647:15)                        
    at ChildProcess.emit (events.js:98:17)                                       
    at maybeClose (child_process.js:755:16)                                      
    at Socket.<anonymous> (child_process.js:968:11)                              
    at Socket.emit (events.js:95:17)                                             
    at Pipe.close (net.js:465:12)                                                

Test OS X

We'll eventually switch over to D-Bus, though I'm not sure it'll work with OS X.

Might have to keep the old method of executing binaries and parsing output, but instead of relying on wpa_supplicant, instead rely on the following:

/System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport 

Nomenclature

Come up with a common naming convention and stick with it. Connect or Join? Disconnect or Leave?

Enable and Disable DHCP

Enable dhcpcd on the interface, which will get us an IP address. This is an event which the app would probably execute once a connection to a network is made.

TypeError: Cannot read property 'ssid' of undefined

../node-wireless/app.js:97
console.log(("[JOIN]"+network.ssid+"["+network.address+"]")

I get the following error running on a Raspberry Pi, running node V0.10.16.

Before that error I get the following output:

[PROGRESS] Enabling wireless card...
[PROGRESS] Wireless card enabled.
[PROGRESS] Starting wireless scan...
[ COMMAND] sudo iwlist wlan0 scan
[ COMMAND] sudo iwconfig wlan0
[PROGRESS] Wireless scanning has commenced.

If I manually run the commands I get valid results. I am using an RTL8188CUS WLAN Adapter.

Better Sample App

The sample app should have some more features.

I'd like it to run, connect to any open network it finds, get an IP address, find out its public ip address, and log everything it found. Should also be able to check for GPS coordinates.

Ideally, one could drive around with this running on a machine in their car, and automatically connect and disconnect without any errors, which I feel would be a great example of the features of the project.

Get Public IP: http://ip.thomashunter.name

Fix callbacks

Some callbacks (e.g. joining networks) have a success and failure callback, like this was jQuery or something.

Other times we don't pass error arguments to callbacks. Or sometimes we exit the process instead of failing a callback.

Fix dat shit, yo!

Setting Object Merge Issues

The settings object isn't merging as expecting; if one of the commands is missing from the passed in object, the one in the existing object doesn't survive the merge.

Problems connecting to wifi

Hi,

I have just started using your module in my hobby project, and after running your sample code I notice strange behavior on my system. If I try to connect to a network with ssid XYZ, I don't get any errors and the wifi doesn't connect to that network. ir. the callback doesn't get executed.

Now after that if I manually try to connect to the same network using ubuntu's menu I cannot connect until I restart my laptop.

I tried

sudo service network-manager restart

sudo service networking restart

but that doesn't solve the problem.

I tried this code on MAC OS and I still had the same problem. is it a known issue?

Ubuntu: 16 04 LTS / 14 04 LTS
MacOSX El Capitan 10.11.6

Thanks and Regards
Nikhil

Change method for interacting with WiFi hardware

Currently, the module runs a bunch of commands over and over. This means we need to wait for the command to finish before we get the results. This can take many seconds, and then we send a "burst" of network found events, etc.

What we should do, is find a better way to talk to the hardware, and be able to trigger an event every single time the device sees a wireless packet.

I have absolutely no idea how to do this. Someone once said something about dmesg or something similar, but I'm still pretty lost.

Unstupidify event emmitter

It's not common Node practice for event emitter calls to have error arguments. They instead emit error events.

FIXIT

Trigger Connect Event

Need to trigger an event when we connect to a network. Should just be able to run iwconfig.

Also, should we trigger multiple events for different stages of connection?

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.