-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.ts
51 lines (39 loc) · 1.1 KB
/
index.ts
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
47
48
49
import * as child_process from "child_process";
import * as Promise from "bluebird";
interface IScan {
essid: string;
mac: string;
signal: string;
}
type INetworkType = 'wifi' | 'wired'
interface INetwork {
type: INetworkType;
mac: string;
interface: string;
essid?: string;
scan?: IScan[];
ip?: string;
gateway?: string;
}
export default function netw() {
return new Promise<INetwork[]>(function(resolve, reject) {
let callbacked = false;
const timo = setTimeout(function() {
if (!callbacked) {
reject("timeout error");
}
}, 20000);
child_process.exec(__dirname + "/scripts/linux/network.sh",
function(error, stdout, stderr) {
callbacked = true;
clearTimeout(timo);
if (error && error !== null) {
reject('AAA'+error);
} else if (stderr) {
reject(stderr);
} else {
resolve(JSON.parse(stdout.toString()));
}
});
});
};