-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
61 lines (51 loc) · 1.8 KB
/
main.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
const cli = require('command-line-args');
const find = require('local-devices');
const portscanner = require('portscanner')
const EXIT_SUCCESS = 0;
const EXIT_FAILURE = 1;
const optionDefinitions = [
{ name: 'send', alias: 's', type: Boolean },
{ name: 'receive', alias: 'r', type: Boolean },
{ name: 'file', alias: 'f', type: String },
{ name: 'output', alias: 'o', type: String },
{ name: 'address', alias: 'i', type: String },
{ name: 'port', alias: 'p', type: String },
{ name: 'list', alias: 'l', type: Boolean },
{ name: 'checkhosting', alias: 'h', type: Boolean }
];
const options = cli(optionDefinitions);
if (options.list) {
find().then(devices => {
devices.forEach(device => {
if (options.checkhosting) {
portscanner.checkPortStatus(9020, device.ip).then(status => {
if (status.toLocaleLowerCase() == 'open' || status.toLocaleLowerCase() == 'closed') {
console.log("!!Device is hosting file with Slide!!")
printDevice(device);
}
});
} else {
printDevice(device);
}
});
}).finally(() => process.exit(EXIT_SUCCESS));
}
function printDevice(device) {
console.log("name: " + device.name);
console.log("ip: " + device.ip);
console.log("mac: " + device.mac);
console.log("");
}
const PORT = parseInt(options.port);
if (options.send) {
const fileToSend = options.file;
const server = require('./server/server');
server(PORT, String(fileToSend));
} else if (options.receive) {
const outputPath = options.output;
const ip = options.address;
const client = require('./client/client');
client(ip, PORT, outputPath);
} else {
//process.exit(EXIT_FAILURE);
}