【发布时间】:2021-01-14 09:25:09
【问题描述】:
我需要获取谁向 nodeJS 服务器发出请求的信息(私有 IP 地址和 MAC)。这是在 Intranet 上运行的,所以我想我可以通过某种方式获取 MAC 数据,而来自os.networkinterfaces() or req.connection 的 ip 对我没有用,因为它们分别给了我服务器或公共 ip。
【问题讨论】:
标签: node.js ip-address
我需要获取谁向 nodeJS 服务器发出请求的信息(私有 IP 地址和 MAC)。这是在 Intranet 上运行的,所以我想我可以通过某种方式获取 MAC 数据,而来自os.networkinterfaces() or req.connection 的 ip 对我没有用,因为它们分别给了我服务器或公共 ip。
【问题讨论】:
标签: node.js ip-address
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: '...' }
]
*/
})
【讨论】: