如何在node js中获取客户端的mac地址?
How to get mac address of client in node js?
是否可以从传入的请求对象中获取 mac 地址?
我的应用程序将在同一子网上本地使用,并且它在 nginx 代理后面运行。
您需要一个访问 ARP table 的工具(一个 table 包含您本地网络中的 MAC IP 地址)。像这样 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...
}
是否可以从传入的请求对象中获取 mac 地址? 我的应用程序将在同一子网上本地使用,并且它在 nginx 代理后面运行。
您需要一个访问 ARP table 的工具(一个 table 包含您本地网络中的 MAC IP 地址)。像这样 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...
}