-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathnic.js
42 lines (36 loc) · 1.02 KB
/
nic.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
var readlineSync = require('readline-sync');
var os = require('os');
module.exports.IPs = function() {
var networkInterfaces = os.networkInterfaces();
var cortanalocalIP = [];
var nics = [];
var ips = [];
var n = 0;
Object.keys(networkInterfaces).forEach(function(nic) {
for(var s = 0; s < networkInterfaces[nic].length; s++) {
if (!networkInterfaces[nic][s].internal && networkInterfaces[nic][s].family == 'IPv4') {
ips[n] = networkInterfaces[nic][s].address;
nics[n] = nic;
n++;
}
}
});
if (n > 1) {
console.log('Interfaces: ')
for(var i = 0; i < n; i++) {
console.log('(' + i + ') ' + nics[i] + ' ' + ips[i]);
}
console.log('(' + i + ') All');
var input;
do {
input = readlineSync.question('Choose one interface: ');
} while(input > n || input < 0);
if (input == n)
cortanalocalIP = ips;
else
cortanalocalIP.push(ips[input]);
} else {
cortanalocalIP.push(ips[0]);
}
return cortanalocalIP;
}