forked from hobbyquaker/check_speedport
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
executable file
·33 lines (30 loc) · 1010 Bytes
/
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
#!/usr/bin/env node
const request = require('request');
const time = (new Date()).getTime();
const rand = Math.floor(Math.random() * 1000);
request({
method: 'GET',
url: 'http://speedport.ip/data/Status.json?_time=' + time + '&_rand=' + rand + '&_lang=DE',
json: true,
headers: {
Referer: 'http://speedport.ip/html/login/status.html?lang=de'
}
}, (err, res, body) => {
if (err) {
console.log(err.toString());
process.exit(2);
} else {
const data = {};
body.forEach(val => {
data[val.varid] = val.varvalue;
});
console.log('Status:', data.status, ' DSL Link:', data.dsl_link_status, ' Downstream:', data.dsl_downstream, 'kbit/s Upstream:', data.dsl_upstream, 'kbit/s');
if (data.status !== 'online') {
process.exit(2);
} else if (data.dsl_downstream < 48000 || data.dsl_upstream < 9750) {
process.exit(1);
} else {
process.exit(0);
}
}
});