-
Notifications
You must be signed in to change notification settings - Fork 1
/
save_cache.js
44 lines (36 loc) · 1.13 KB
/
save_cache.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
const ewelink = require('ewelink-api');
const Zeroconf = require('ewelink-api/src/classes/Zeroconf');
const yargs = require('yargs');
const argv = yargs
.option('email', {
alias: 'e',
description: 'Ewelink registered email',
})
.option('password', {
alias: 'p',
description: 'Ewelink account password',
})
.default("region", "us") // ewelink account region
.help()
.alias('help', 'h')
.argv;
const myIp = Object.values(require('os').networkInterfaces()).reduce((r, list) => r.concat(list.reduce((rr, i) => rr.concat(i.family==='IPv4' && !i.internal && i.address || []), [])), []);
console.log("My local IP is: " + myIp);
var password = argv.password;
if (!("password" in argv)) {
password = process.env.PASSWORD;
}
(async () => {
const connection = new ewelink({
email: argv.email,
password: password,
region: argv.region,
});
console.log("Saving devices cache");
await connection.saveDevicesCache();
console.log("Saving arp table");
await Zeroconf.saveArpTable({
ip: myIp.toString()
});
console.log("Done!");
})();