-
Notifications
You must be signed in to change notification settings - Fork 0
/
uknock-e.js
41 lines (38 loc) · 1.07 KB
/
uknock-e.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
//easy version of uknock since knocker is used
var hosts = [];
var ports = [];
var knocker = require('knocker')
var ping = require('ping');
function check() {
hosts.forEach(function (host) {
setTimeout(function () {
ping.promise.probe(host)
.then(function (res) {
console.log(res.alive)
check();
if (res.alive === false) {
console.log("entering")
opening();
// return(res.alive);
// exports.check = res.alive
}
});
}, 10000)
});
}
check();
function opening (){
let i = 0
setTimeout(function open(){
if (i<ports.length){
knocker.setTarget('')
.knock(ports[i])
console.log("Knocking " + ports[i])
i++;
open()
}else{
console.log("Knocking completed");
return("opened");
}
},100)
}