Cross-platform local network library to scan lan and determine device informations (using ping and arp)
npm install lan-discovery``bash`
$ npm install lan-discovery --save
$ node test.js
Low-impact method: ARP broadcast first to discover active devices, then ping only on discovered IPs.
`javascript
const LanDiscovery = require('lan-discovery');
let discovery = new LanDiscovery({ verbose: false, timeout: 60 });
// Listen to ARP discovery events
discovery.on(LanDiscovery.EVENT_ARP_RESPONSE, (device) => {
console.log('ARP discovered:', device.ip, device.mac);
});
// Listen to ping and device info events
discovery.on(LanDiscovery.EVENT_DEVICE_INFOS, (device) => {
console.log('Device info:', device); // { ip, mac, name, alive: true }
});
discovery.on(LanDiscovery.EVENT_DEVICES_INFOS, (devices) => {
console.log('All devices:', devices.length, 'found');
});
let myInterface = await discovery.getDefaultInterface();
await discovery.startHybridScan({
networkInterface: myInterface,
timeout: 3000,
interval: 100
});
`
Note:
- Linux/macOS/Windows: If no administrator rights, throws an error.
- Linux/macOS: For ARP broadcast, use scan-arp command (sudo apt install arp-scan)
- Windows: For ARP broadcast, use third_party/scan-arp.exe (packed in the application)
`javascript
const LanDiscovery = require('lan-discovery');
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 = LanDiscovery.cidrRange(myInterface.cidr);
discovery.startScan({ ipArrayToScan: tabIP, interval: 100 });
`
---
---
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
---
Start the lan scan (Node ICMP Requests) and return promise resolving the network scan.
Requirements:
- All platforms (priority): raw-socket package for efficient ping session via net-pingraw-socket
- The package is included in dependencies and will be installed automatically
Start hybrid scan: Instead of scanning all IPs, ARP broadcast first (L2 low impact), then ping (L3) only on discovered IPs.
Return promise resolving the network scan.
Requirements:
- All platforms (priority): raw-socket package for efficient ping session via net-pingraw-socket
- The package is included in dependencies and will be installed automaticallyarp-scan
- Windows: administrator rights
- Linux/macOS: administrator rights, command (sudo apt install arp-scan`)
---
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
On linux/macOS, we use arp-scan command available at https://github.com/royhills (Roy Hills)
On windows, we use arp-scan.exe available at https://github.com/QbsuranAlang (Qbsuran Alang)
MIT