$ npm install lan-discovery --save
$ node test.js
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 });
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
Retrieves the network's arp table
Get all informations about a device identified by his IP address
Get the IP address for given MAC address Warning : can return null if the lan has not been scanned recently
Get the MAC address for given IP address Warning : can return null if you haven't previously send a ping request
Get hostname from ip address
Return active network informations
Checks if an IP address is valid
Checks if a MAC address is valid
Ping an ip address with os ping command (slower but usefull to update the os arp table)
Start the lan scan (Node ICMP Requests) and return the class object
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
MIT