-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
79 lines (69 loc) · 1.8 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
const { request } = require('http')
/**
* url without `http://` or `https://`
*
* @param {String} url
*/
function pingger(url){
if(url == null) {
console.log("your url");
process.exit(1);
}
var sites = url.split(',');
console.log(sites);
for(var i = 0; i < sites.length; i++) {
console.log("SITE: " + sites[i]);
var ping = new anubisPinger(sites[i]);
ping.sendRequest();
}
}
/**
* site without `http://` or `https://`
*
* @param {String} site
* @return {Boolean}
*/
class anubisPinger {
constructor(site) {
var self = this;
self.site = site;
self.sendRequest = function () {
console.log("SENDING REQUEST TO: " + self.site);
var connect_host = self.site;
var connect_path = '/';
var options = {
agent: false,
host: connect_host,
port: 80,
path: connect_path,
method: 'GET'
};
var post_req = request(options, function (res) {
var d = '';
res.setEncoding('utf8');
res.on('data', function (chunk) {
d += chunk;
});
res.on('end', function () {
console.log("REQUEST RESPONSE FROM " + self.site + ": Status Code " + res.statusCode);
setTimeout(self.sendRequest, self.getRandomTime());
});
});
post_req.on('error', function (e) {
console.log("ERROR: web request to " + site + " failed");
console.log(e);
setTimeout(self.sendRequest, self.getRandomTime());
});
post_req.end();
};
self.getRandomTime = function () {
var min = 600 * 1000;
var max = 1200 * 1000;
var seed = max - min;
var r = Math.floor((Math.random() * seed) + min);
console.log("Sleeping For: " + r / 1000 + " Seconds");
return r;
};
}
}
module.exports = pingger