How to detect 4G dongle(s) connected to my computer using NodeJs

112 views Asked by At

How can I detect 4G dongle(s) connected to my computer using NodeJS?

I tried the following code:

var os = require('os');
var allNetworkInterfaces = os.networkInterfaces();
console.log(allNetworkInterfaces);

It works, but I got all network interfaces... I would like to get a list with my 4G dongles only. Knowing that I could have either 1 dongle, or several dongles connected to the same computer, as well as other USB hardwares connected.

1

There are 1 answers

0
Hitesh Lala On

After installing the usb package by running npm install usb I was able to get a list of usb devices using the following code:

const usb = require('usb');
const devices = usb.getDeviceList();
console.log( devices );

You will have to go through that list and decide which is your "4G dongle".