簡體   English   中英

在 NodeJS 服務器上獲取本地網絡 ip 地址

[英]Get local network ip addresses on NodeJS server

我需要獲取向 nodeJS 服務器發出請求的信息(私有 IP 地址和 MAC)。 這是在 Intranet 上運行的,所以我想我可以以某種方式獲取 MAC 數據,並且來自os.networkinterfaces() or req.connection的 ip 對我os.networkinterfaces() or req.connection用,因為它們分別給了我服務器或公共 ip。

本地設備

凈功率

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: '...' }
  ]
  */
})

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM