在 NodeJS 服务器上获取本地网络 ip 地址
Get local network ip addresses on NodeJS server
我需要获取向 nodeJS 服务器发出请求的信息(私有 ip 地址和 MAC)。这是 Intranet 上的 运行,所以我想我可以通过某种方式获取 MAC 数据,而来自 os.networkinterfaces() or req.connection
的 ip 对我没有用,因为他们给了我服务器或 [=15] =] ip 分别.
Npm
npm install local-devices
例子
// Using a transpiler
import find from 'local-devices'
// Without using a transpiler
const find = require('local-devices');
// Find all local network devices.
find().then(devices => {
devices /*
[
{ name: '?', ip: '192.168.0.10', mac: '...' },
{ name: '...', ip: '192.168.0.17', mac: '...' },
{ name: '...', ip: '192.168.0.21', mac: '...' },
{ name: '...', ip: '192.168.0.22', mac: '...' }
]
*/
})
我需要获取向 nodeJS 服务器发出请求的信息(私有 ip 地址和 MAC)。这是 Intranet 上的 运行,所以我想我可以通过某种方式获取 MAC 数据,而来自 os.networkinterfaces() or req.connection
的 ip 对我没有用,因为他们给了我服务器或 [=15] =] ip 分别.
Npm
npm install local-devices
例子
// Using a transpiler
import find from 'local-devices'
// Without using a transpiler
const find = require('local-devices');
// Find all local network devices.
find().then(devices => {
devices /*
[
{ name: '?', ip: '192.168.0.10', mac: '...' },
{ name: '...', ip: '192.168.0.17', mac: '...' },
{ name: '...', ip: '192.168.0.21', mac: '...' },
{ name: '...', ip: '192.168.0.22', mac: '...' }
]
*/
})