npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

mdns-listener-advanced

v3.2.6

Published

mDNS listener, add as many .local hostnames to your computer as you like.

Downloads

4,644,503

Readme

mDNS Listener Advanced

npm package Maintenance version number Actions Status License node-current

:warning: Major update Since version 3.0.0 this package is using a Typescript Implementation and it is fully tested on Mac OS 14.1 and windows 11 and ubuntu 18 If you have any issue feel free to open an issue here

Advanced mDNS Listener to add and listen .local hostnames in your network compatible with zeroconf, bonjour, avahi

I recommand using this 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 :wink: I can make you an offer.

  • Note that mdns-listener-advanced includes a bonjour publisher since version 3.1.0

Requirements

  • Node 18 or later (we recommend using NVM) this package is using Node v20

Installation

npm install mdns-listener-advanced

Usage

JS

Fully tested on windows 11, ubuntu 18 and Mac OS 14.

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
});

:white_check_mark: Fully tested

ts

import { Core } from './Core';
import { Device, emittedEvent } from './types';
const ref = 'MyDevice2';
const mdns = new Core([ref], null, {
  debug: false,
  disableListener: false,
});

const event = mdns.listen();
mdns.publish(ref);
// Basic response of 'MyDevice2'
event.on(emittedEvent.RESPONSE, (found_hostnames: Array<Device>) => {
  mdns.info('found hostnames', found_hostnames);
  // mdns.stop();// To stop the listener
});
// Array of objects of different types
event.on(emittedEvent.RAW_RESPONSE, (hosts: Array<object>) => {
  mdns.info('raw response', hosts);
});
//Error occured
event.on(emittedEvent.ERROR, (error: Error) => {
  mdns.info('error', error);
  // mdns.stop();// To stop the listener
});
  • To Stop listening to the event use :
mdns.stop();

emittedEvent Const since v3.2.0:

| Name | Descripti | | --------------------------------- | ---------------------------------------- | | emittedEvent.RESPONSE | Emits when an mdns device is discovered | | emittedEvent.RAW_RESPONSE | Emits raw data of the mdns response | | emittedEvent.ERROR | Emits on any errors |

Configuration

Method 1

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.

Method 2

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.

Publish and Unpublish a hostname

To publish a hostname you can use this example :

import { Core } from "mdns-listener-advanced";
const ref = "MyDevice2";
const mdns = new Core();
mdns.publish(ref);
mdns.unpublishAll();// You can unpublish using this function

Output:

ℹ️ MDNS ADVANCED A hostname have been published with options {
  port: 3000,
  name: 'MyDevice2',
  type: 'TXT',
  txt: {
    id: '"510f56fb-cb61-45d6-8e01-be4ed49405bb"',
    ipv4: '"192.168.2.11"'
  }
}

Note that a warning will appear if you initialise the Core of mdns-listener-advanced without providing a hostname list or ~/.mdns-hosts file path.

⚠️ MDNS ADVANCED Hostnames or path to hostnames is not provided, listening to a host is compromised!
  • At the moment you cannot unpublish services undividually or by hostname and there might be a way using the included bonjour library.

Details :

| 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 default value is false | | new advanced_mdns(..,..,options) | options | {disableListener:boolean} | Disable listener the default value is false set it to true to use only publish mode | | .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 | | .publish(hostname) | hostname | string | to publish an mdns host protocol | | .unpublishAll() | | | to unpublish all mdns host protocol |

Known / Reported issues :

  • investigating an issue with Bin script confusion not affecting the npm package, only quality

Fixed major security issues :

  • Lot of security issues fixed since and deprecated packages replaced or removed 3.1.9
    • CVE-2020-28469

    • SemVer anomaly

    • resolve-url (deprecated)

    • source-map-resolve (deprecated)

    • source-map-url (deprecated)

    • urix (deprecated)

  • 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 : Will not fix because lodash team are stuborn and insist that npm audit is broken~~
    • Prototype Pollution in lodash Critical : workaround forced upgrade "lodash.template": "^4.5.0"
    • 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 (Fixed)
    • 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)

Want to contribute or have any suggestions or questions?

Contact me on Linkedin Here.

Other notes

Note: The original idea was from @Richie765 https://github.com/Richie765/mdns-listener and got updated and enhanced, few parts of the original code might still exist.