mdns-listener-advanced 3.0.12
Install from the command line:
Learn more about npm packages
$ npm install @aminekun90/mdns-listener-advanced@3.0.12
Install via package.json:
"@aminekun90/mdns-listener-advanced": "3.0.12"
About this version
Advanced mDNS Listener to add and listen .local hostnames in your network compatible with zeroconf, bonjour, avahi
I recommand using python publisher https://github.com/aminekun90/python_zeroconf_publisher since this code is fully compatible with it, if you dont have access to it you can contact me further bellow 😉 I can make you an offer.
Note: The original idea was from @Richie765 https://github.com/Richie765/mdns-listener and got updated and enhanced, few parts of the original code still exist, recently updated to typescript.
npm install mdns-listener-advanced
Fully tested on windows 11, ubuntu 18 and Mac OS 13.
var mdnsListenerAdvanced = require("mdns-listener-advanced");
const mdns = new mdnsListenerAdvanced.Core(['MyDevice2']);
const event = mdns.listen();
event.on('response', (found_hostnames) => {
console.log('found_hostnames', found_hostnames);
// mdns.stop();// To stop the listener
});
event.on('error', (error) => {
console.log('error', error);
// mdns.stop();// To stop the listener
});
✅ Fully tested
import { Core } from "mdns-listener-advanced";
const mdns = new Core(['MyDevice2']);
const event = mdns.listen();
event.on('response', (found_hostnames) => {
console.log('found_hostnames', found_hostnames);
// mdns.stop();// To stop the listener
});
event.on('error', (error) => {
console.log('error', error);
// mdns.stop();// To stop the listener
});
- To Stop listening to the event use :
mdns.stop();
Provide hostnames list in the constructor like this :
var mdnsListenerAdvanced = require("mdns-listener-advanced");
const mdns = new mdnsListenerAdvanced.Core(['MyDevice1','MyDevice2']);
The file .mdns-hosts is created automatically.
Add and Edit the file named .mdns-hosts, this file must be in your HOME directory for windows [HDD]:\Users\<username>\.mdns-hosts
and for linux/Mac ~/.mdns-hosts
, place hostnames ending on separate lines like so:
myhost1
myhost2
You can specify the hostnames that you want to detect !
Whenever you change this file, you should restart the service.
Functions | Params | Type | Description |
---|---|---|---|
new mdnsListenerAdvanced.Core(['MyDevice2']); |
hostsList | Array<string> |
List of hostnames |
new advanced_mdns(..,mdnsHostsPath) |
mdnsHostsPath | string |
Full path of your .mdns-hosts (not available) |
new advanced_mdns(..,..,options) |
options | {debug:boolean} |
Enable debug |
.listen().on(event,callback(object)) |
event | string |
To catch a response event when set to "response"
|
callback | function(object) |
callback to do custome code | |
object | object |
a received object i.e {MyDevice1:{...}}
|
|
.stop() |
to stop the event listener |
- Issue on version 3.0.9 module not found (Fixed since 3.0.11)
- Keeping eye on some Security issues ( will be patched when patched new version of those packages is available):
- Prototype Pollution in lodash Critical : wont fix because lodash team are stuborn and insist that npm audit is broken
- glob-parent before 5.1.2 vulnerable to Regular Expression Denial of Service in enclosure regex High (Fixed)
- yargs-parser Vulnerable to Prototype Pollution Moderate
- Memory Exposure in concat-stream Moderate (Fixed)
- Regular Expression Denial of Service (ReDoS) in braces Low (Fixed)
- Regular Expression Denial of Service in braces Low (Fixed)
Contact me on Linkedin Here.