1.0.3 • Published 6 months ago

@davidwells/wifi-utils v1.0.3

Weekly downloads
-
License
ISC
Repository
-
Last release
6 months ago

wifi-utils

A Node.js utility package for scanning, connecting to, and managing Wi-Fi networks across different operating systems.

Fork of https://www.npmjs.com/package/node-wifi with updates for newer macOS versions and some additional features.

Features

  • Scan for available Wi-Fi networks
  • Connect to Wi-Fi networks with password authentication
  • Get current Wi-Fi connection details
  • Cross-platform support (macOS, Windows, Linux)
  • Automatic fallback mechanisms for different OS implementations
  • Retries on connection failure

Installation

npm install @davidwells/wifi-utils

Usage

Scanning for Wi-Fi Networks

const { searchForWifi } = require('@davidwells/wifi-utils');

// Basic usage
searchForWifi()
  .then(networks => {
    console.log('Available networks:', networks);
  })
  .catch(error => {
    console.error('Error scanning for networks:', error);
  });

// With callback and options
searchForWifi(
  (networks) => {
    console.log('Found networks:', networks);
  },
  {
    timeoutDuration: 60000, // 60 seconds timeout
    scanInterval: 2000     // Scan every 2 seconds
  }
)
  .then(networks => {
    console.log('Final networks:', networks);
  });

Connecting to a Wi-Fi Network

const { connectToWifi } = require('@davidwells/wifi-utils');

connectToWifi({
  ssid: 'MyNetwork',
  password: 'MyPassword' // optional
})
  .then(result => {
    console.log('Connected successfully!');
    console.log('Network details:', result);
  })
  .catch(error => {
    console.error('Connection failed:', error);
  });

API Reference

searchForWifi(callback, options)

Scans for available Wi-Fi networks.

  • callback (Function, optional): Function called with found networks
  • options (Object, optional):
    • timeoutDuration (Number): Maximum time to scan in milliseconds (default: 60000)
    • scanInterval (Number): Time between scans in milliseconds (default: 2000)
  • Returns: Promise resolving to array of network objects

connectToWifi(options)

Connects to a Wi-Fi network.

  • options (Object):
    • ssid (String): Name of the network to connect to
    • password (String): Network password
  • Returns: Promise resolving to connection details

OS Compatibility

This package automatically detects the operating system and uses the appropriate method for Wi-Fi operations:

  • On macOS: Uses the airport command with fallback to system_profiler
  • On Windows: Uses the Windows Wi-Fi API
  • On Linux: Uses the Linux Wi-Fi API

License

MIT

1.0.3

6 months ago

1.0.2

6 months ago

1.0.1

6 months ago

1.0.0

6 months ago