-
Notifications
You must be signed in to change notification settings - Fork 1
/
monitor.js
executable file
·46 lines (34 loc) · 932 Bytes
/
monitor.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
#!/usr/bin/env node --use_strict
const mdns = require('multicast-dns')()
// Set process name
process.title = process.title = 'mdns-monitor';
mdns.on('query', function(query) {
console.log('query:', query);
const { questions } = query;
if(questions) {
questions.forEach(question => {
const { name, type } = question;
if (type ==='PTR') return;
if (type ==='TXT') return;
console.log(`question: ${ name } [${ type }]`);
});
}
else {
console.log('query:', query);
}
});
mdns.on('response', function(response) {
// console.log('response:', response);
const { answers } = response;
if(answers) {
answers.forEach(answer => {
const { name, type, data } = answer;
if (type ==='PTR') return;
if (type ==='TXT') return;
console.log(`answer: ${ name } [${ type }] => ${ data }`);
});
}
else {
console.log('response:', response);
}
});