@dderevjanik/termux-api
Version:
This library allows you to interact with your Android device from Node.js using termux-api
84 lines (72 loc) • 1.72 kB
text/typescript
import { exec } from "child_process";
export interface WifiNetworkInfo {
/**
* 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 IP address assigned to the device.
* @example "192.168.31.27"
*/
ip: string;
/**
* The link speed of the Wi-Fi network in Mbps.
* @example 286
*/
link_speed_mbps: number;
/**
* The MAC address of the device.
* @example "02:00:00:00:00:00"
*/
mac_address: string;
/**
* The network ID of the Wi-Fi network.
* @example 54
*/
network_id: number;
/**
* The RSSI (Received Signal Strength Indicator) of the Wi-Fi network.
* @example -53
*/
rssi: number;
/**
* The SSID (Service Set Identifier) of the Wi-Fi network.
* @example "Prizemie 1"
*/
ssid: string;
/**
* Indicates if the SSID is hidden.
* @example false
*/
ssid_hidden: boolean;
/**
* The supplicant state of the Wi-Fi network.
* @example "COMPLETED"
*/
supplicant_state: string;
}
/**
* Get information about the current wifi connection
*/
export async function wifiConnectionInfo(): Promise<WifiNetworkInfo> {
return new Promise<WifiNetworkInfo>((resolve, reject) => {
const command = `termux-wifi-connectioninfo`;
exec(command, (error, stdout, stderr) => {
if (error) {
return reject(`Error: ${error.message}`);
}
if (stderr) {
return reject(`Error: ${stderr}`);
}
const output = stdout.trim();
const networks: WifiNetworkInfo = JSON.parse(output);
return resolve(networks);
});
});
}