Node JS Find all devices connected to the local network

Viewed 3103

Hi guys Im trying to find a package or a code to find all connected devices on local network, I want to determine a list of all printers, and other devices on my network.

I found these two packages:

https://www.npmjs.com/package/local-devices

But it requires net-tools to be installed on my pc, to have arp command available

And the other one is

https://github.com/jas-/node-libnmap

But these other one requires Nmap to be installed, is there any solution in pure node ?

1 Answers

If you want to run on any platform, you need an universal third party application, though arp is available in most OS (Windows/Linux/Mac). If you want to run only on Windows you can use net view using exec.

const { exec } = require('child_process');
exec('net view', (error, stdout, stderr) => {
  var servers = stdout.match(/(\\\\\S+)/g);
  console.log("Servers available:");
  for (var server of servers) {
    console.log(server);
  }
});
Related