Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .jshintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"node" : true,
"esversion": 6
}
32 changes: 25 additions & 7 deletions lib/win.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,37 @@
const execa = require('execa');

module.exports = ssid => {
// Assumes only one connected WLAN interface, which is likely
const cmd = 'netsh';
const args = ['wlan', 'show', 'profile', `name=${ssid}`, 'key=clear'];
const args = ['wlan', 'show', 'profile', 'name=*'];

return execa.stdout(cmd, args).then(stdout => {
let ret;
let profile;

ret = /^\s*Key Content\s*: (.+)\s*$/gm.exec(stdout);
ret = ret && ret.length ? ret[1] : null;
// Get profile for our SSID
let re = new RegExp('(?:Name\\s+: "?)(.+?$)(?:[\\s\\S][^=]*?(?=\\n.*?"' + ssid + '"))', "gm");
profile = re.exec(stdout)[1];
profile = profile && profile.length ? profile : null;

if (!ret) {
throw new Error('Could not get password');
if (!profile) {
throw new Error('Could not get profile name');
}

return ret;
return profile;
})
.then(function(profile) {
const args = ['wlan', 'show', 'profile', `name=${profile}`, 'key=clear'];
return execa.stdout(cmd, args).then(stdout => {
let ret;

ret = /^\s*Key Content\s*: (.+)\s*$/gm.exec(stdout);
ret = ret && ret.length ? ret[1] : null;

if (!ret) {
throw new Error('Could not get password');
}

return ret;
});
});
};