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

lan-discovery

v1.0.1

Published

Cross-platform local network library to scan lan and determine device informations (using ping and arp)

Downloads

18

Readme

lan-discovery

Installation

$ npm install lan-discovery --save
$ node test.js

Usage

Example

const LanDiscovery = require('lan-discovery');
const CidrRange = require('cidr-range');
let discovery = new LanDiscovery({ verbose: false, timeout: 60 });
discovery.on(LanDiscovery.EVENT_DEVICE_INFOS, (device) => {
	console.log('--> event '+ LanDiscovery.EVENT_DEVICE_INFOS +' :\n', device);
});

let myInterface = await discovery.getDefaultInterface();
let tabIP = CidrRange(myInterface.cidr);
discovery.startScan({ ipArrayToScan: tabIP });

EVENTS

EVENT_SCAN_RESPONSE : one device just responded to ping EVENT_DEVICE_INFOS : we juste retrieve one device informations EVENT_SCAN_COMPLETE : ping scan complete EVENT_DEVICES_INFOS : we retrieve all devices informations


async arpTable(): Promise<Array>

Retrieves the network's arp table


async deviceInfos(): Promise<Object>

Get all informations about a device identified by his IP address


async deviceIP(mac: string): Promise<string | null>

Get the IP address for given MAC address Warning : can return null if the lan has not been scanned recently


async deviceMAC(ip: string): Promise<string | null>

Get the MAC address for given IP address Warning : can return null if you haven't previously send a ping request


async deviceName(ip: string): Promise<string | null>

Get hostname from ip address


async getDefaultInterface(): Promise<Object>

Return active network informations


isIP(ip: string): boolean

Checks if an IP address is valid


isMAC(mac: string): boolean

Checks if a MAC address is valid


async osPingCommand(ip: string): Promise<bool | null>

Ping an ip address with os ping command (slower but usefull to update the os arp table)


startScan(): This

Start the lan scan (Node ICMP Requests) and return the class object


Credits

This librarie is heavyly inspired from theses modules :

  • device-discovery (Mark Tiedemann)
  • arpping (haf-decent)
  • @network-utils/arp-lookup (Justin Taddei)
  • @network-utils/tcp-ping (Justin Taddei)
  • default-gateway (Sindre Sorhus)

... but re-writed to fit my needs :

  • get ip/mac/name with one cross platform librarie (at least linux and windows)
  • no more nmap dependencies
  • use of nodejs ping implementation (net-ping) to keep performance
  • use of ES8 keyword async/await
  • use class and class inheritance
  • use of event pattern

License

MIT