Using the command line netsh wlan show interfaces shows the output below, however I'm trying to make a script where it can pull Profile : 3MobileWiFi-3D71 and only return the result after the : so then I can make a JS Script to then use this data with the following command line Netsh wlan show profile name="${DeviceFromInterfaces}" key=clear which then will only return the following data I need: Key Content : REDACTED
How would I get this data using this module:
child_process which uses exec to run most of the stuff aforementioned.
Security settings
-----------------
Authentication : WPA2-Personal
Cipher : CCMP
Authentication : WPA2-Personal
Cipher : GCMP
Security key : Present
Key Content : REDACTED
[Interfaces]
There is 1 interface on the system:
Name : WiFi
Description : Intel(R) Dual Band Wireless-AC 3160
GUID : REDACTED
Physical address : REDACTED
State : connected
SSID : 3MobileWiFi-3D71
BSSID : REDACTED
Network type : Infrastructure
Radio type : 802.11n
Authentication : WPA2-Personal
Cipher : CCMP
Connection mode : Profile
Channel : 11
Receive rate (Mbps) : 65
Transmit rate (Mbps) : 65
Signal : 90%
Profile : 3MobileWiFi-3D71
Hosted network status : Not available
I'd probably use child_process.spawn or child_process.spawnSync to run the commands, and then use regular expressions to parse the output. Here's what that would look like for the first command:
import {spawn} from 'child_process';
let stdOut = '';
const evaluator = spawn('netsh', ['wlan', 'show', 'interfaces']);
evaluator.stdout.on('data', (data) => {
stdOut += data.toString();
});
evaluator.on('close', () => {
const regex = /^profile.*:\s/i;
const profile = stdOut
.split('\n')
.map((ln) => ln.trim())
.find((ln) => ln.match(regex))
.replace(regex, '');
console.log(profile);
});
The callback provided to the close event on evaluator would return the profile name, after which you could take that output and pipe it into your next command — using the same type of logic to parse out the necessary data.