forked from PeterJCLaw/nwatchlive
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathservices.default.js
More file actions
43 lines (42 loc) · 1.21 KB
/
Copy pathservices.default.js
File metadata and controls
43 lines (42 loc) · 1.21 KB
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
var dns = require('dns');
addWatcher('Internet uplink', watchPing('8.8.8.8'));
addWatcher('UoS DNS (Infoblox)', watchPing('152.78.111.81'))
// addWatcher('Internet uplink (v6)', watchPing6('2001:4860:4860::8888'));
addWatcher('DNS', function(ack, err) {
dns.resolve('google.com', function(e, addresses) {
if (e) {
err(e.message);
} else {
if (addresses.length == 0) {
err("no records");
} else {
ack();
}
}
});
});
/**
* Check a non-existent name to ward off captive portals.
*/
addWatcher('Negative DNS', function(ack, err) {
dns.resolve('nonexistant.example.com', function(e, addresses) {
if (e) {
if (
e.code == 'ENOTFOUND' ||
e.code == 'ETIMEOUT' ||
e.errno == 'ENOTFOUND' ||
e.errno == 'ETIMEOUT'
) {
ack();
} else {
err(e.message);
}
} else {
if (addresses.length > 0) {
err("false address generated: " + addresses[0]);
} else {
err("false positive (empty) record");
}
}
});
});