UNPKG

@dderevjanik/termux-api

Version:

This library allows you to interact with your Android device from Node.js using termux-api

66 lines (57 loc) 1.43 kB
import { exec } from "child_process"; export interface WifiNetwork { /** * The BSSID of the Wi-Fi network. * @example "9c:9d:7e:45:bf:dc" */ bssid: string; /** * The frequency of the Wi-Fi network in MHz. * @example 2462 */ frequency_mhz: number; /** * The RSSI (Received Signal Strength Indicator) of the Wi-Fi network. * @example -39 */ rssi: number; /** * The SSID (Service Set Identifier) of the Wi-Fi network. * @example "Prizemie 1" */ ssid: string; /** * The timestamp of the Wi-Fi network scan. * @example 954656432447 */ timestamp: number; /** * The channel bandwidth of the Wi-Fi network in MHz. * @example "20" */ channel_bandwidth_mhz: string; /** * The center frequency of the Wi-Fi network in MHz (optional). * @example 5775 */ center_frequency_mhz?: number; } /** * Get information about the last wifi scan */ export async function wifiScanInfo(): Promise<WifiNetwork[]> { return new Promise<WifiNetwork[]>((resolve, reject) => { const command = `termux-wifi-scaninfo`; exec(command, (error, stdout, stderr) => { if (error) { return reject(`Error: ${error.message}`); } if (stderr) { return reject(`Error: ${stderr}`); } const output = stdout.trim(); const networks: WifiNetwork[] = JSON.parse(output); return resolve(networks); }); }); }