-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
46 lines (36 loc) · 1.25 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
var os = require('os');
var exec = require('child_process').exec;
var getOsxSSID = function getOsxSSID(done) {
var cmd = "/System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport -I | awk '/ SSID/ {print substr($0, index($0, $2))}'";
exec(cmd, done);
};
var getWinSSID = function getWinSSID(done) {
var cmd = "netsh wlan show interfaces | findstr /R /C:\" SSID\"";
exec(cmd, function (error, stdout, stderr) {
var parts = stdout.trim().split(':');
if (parts.length < 2) {
done("No ssid found", "", stderr);
return;
}
done(error, parts[1].trim(), stderr);
});
};
var getLinuxSSID = function getLinuxSSID(done) {
var cmd = "nm-tool | grep \* | grep : | cut -d \":\" -f1 | cut -d \"*\" -f2 ";
exec(cmd, done);
};
module.exports = function detect(cbk) {
var done = function(error, stdout, stderr) {
cbk(error, stdout.trim(), stderr.trim());
}
switch (os.platform()) {
case "darwin":
return getOsxSSID(done);
case "win32":
return getWinSSID(done);
case "linux":
return getLinuxSSID(done);
default:
done('platform not supported : ' + os.platform());
}
};