[英]How to get list of devices connected to my router using node.js
有沒有辦法使用javascript / NodeJS獲取連接到路由器的設備的列表?
您可以使用/proc/net/arp
文件並按如下方式進行解析:
var fs = require('fs');
fs.readFile('/proc/net/arp', function(err, data) {
if (!!err) return done(err, null);
var output = [];
var devices = data.toString().split('\n');
devices.splice(0,1);
for (i = 0; i < devices.length; i++) {
var cols = devices[i].replace(/ [ ]*/g, ' ').split(' ');
if ((cols.length > 3) && (cols[0].length !== 0) && (cols[3].length !== 0) && cols[3] !== '00:00:00:00:00:00') {
output.push({
ip: cols[0],
mac: cols[3]
});
}
}
console.log(output);
});
您也可以嘗試node-libnmap 。 本地同行可以通過:
require('libnmap').nmap('discover', function(err, report){
if (err) throw err
console.log(report)
})
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.