【问题标题】:How to get mac address of client in node js?如何在节点js中获取客户端的mac地址?
【发布时间】:2021-02-03 10:46:57
【问题描述】:

是否可以从传入的请求对象中获取mac地址? 我的应用程序将在同一子网上本地使用,它在 nginx 代理后面运行。

【问题讨论】:

    标签: node.js nginx networking mac-address


    【解决方案1】:

    您需要一个工具来访问 ARP 表(一个包含本地网络中 IP 的 MAC 地址的表)。像这样arp-lookup package。您可以提取传入的请求 ip。然后使用此 IP 通过 arp-lookup 提取 MAC 地址。

    代码是这样的:

    const{ toMAC } = require('@network-utils/arp-lookup');
    
    // ...
    
    async function handleIncomingRequest( req, res ) {
        const ip = req.connection.remoteAddress;
        const mac = await toMAC(ip);
    
        // do stomething with the MAC address...
    }
    

    【讨论】:

      猜你喜欢
      • 2017-10-28
      • 1970-01-01
      • 1970-01-01
      • 2019-07-12
      • 2021-03-18
      • 1970-01-01
      • 1970-01-01
      • 2013-11-07
      • 2013-11-08
      相关资源
      最近更新 更多