-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
48 lines (37 loc) · 1.15 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
"use strict";
const os = require("os");
const ip = require("ip");
const ping = require('ping');
const arp = require("node-arp");
let networks = [];
let myAddress = [];
var interfaces = os.networkInterfaces();
for (let name in interfaces) {
interfaces[name].map((inet) => {
if (inet.internal) return;
if (inet.family != 'IPv4') return;
myAddress.push(inet.address);
for (let i in networks) {
if (networks[i].contains(inet.address)) {
return;
}
}
networks.push(ip.cidrSubnet(inet.cidr))
});
}
// console.log(networks);
networks.map((network) => {
for(let i = ip.toLong(network.firstAddress), l = ip.toLong(network.lastAddress); i < l + 1; i++){
let address = ip.fromLong(i)
if (myAddress.indexOf(address) != -1) continue;
// console.log(address);
ping.sys.probe(address, function(isAlive){
if (!isAlive) return;
arp.getMAC(address, (error, mac) => {
if ( mac.startsWith("b8:27:eb")) {
console.log(address);
}
});
}, {timeout: 1});
}
});