1 | const
|
2 | os = require('os'),
|
3 | net = require('net')
|
4 |
|
5 | module.exports.getExternalNetworkInterface = function () {
|
6 | const
|
7 | networkInterfaces = os.networkInterfaces(),
|
8 | devices = []
|
9 |
|
10 | for (let deviceName of Object.keys(networkInterfaces)) {
|
11 | const networkInterface = networkInterfaces[deviceName]
|
12 |
|
13 | for (let networkAddress of networkInterface) {
|
14 | if (!networkAddress.internal && networkAddress.family === 'IPv4') {
|
15 | devices.push({ deviceName, ...networkAddress })
|
16 | }
|
17 | }
|
18 | }
|
19 |
|
20 | return devices
|
21 | }
|