在 node.js 上获取客户端的 MAC 地址
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19647916/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Getting client's MAC address on node.js
提问by Jorge Ramón
Is there a way to find client's mac address on Node.js? I have been searching about it and i found node-sigar project but it didn't works because it throws a "cannot find module ./build/Release/sigar" error.
有没有办法在 Node.js 上找到客户端的 mac 地址?我一直在搜索它,我找到了 node-sigar 项目,但它没有工作,因为它抛出“找不到模块 ./build/Release/sigar”错误。
回答by WiredPrairie
Unless your code is running on the same LAN segment as the client, you cannot obtain the MAC address of a client. You'd need to likely shell out to a command line tool or native support to gain addresses on the local LAN segment.
除非您的代码与客户端运行在同一 LAN 网段上,否则您无法获取客户端的 MAC 地址。您可能需要使用命令行工具或本机支持来获取本地 LAN 网段上的地址。
For nodejs: https://npmjs.org/search?q=Arp
对于 nodejs:https://npmjs.org/search ?q =Arp
If you try to get remote clients' MAC addresses, you'll end up with the address of a router more than likely.
如果您尝试获取远程客户端的 MAC 地址,则很可能最终会得到路由器的地址。
回答by broofa
The getmac modulewill do this. It calls out to the command line to get the system's network config info and then uses a regex to parse output to find the mac address. The system commands it uses are getmac(Windows) or ifconfig(other platforms).
该getmac模块将做到这一点。它调用命令行以获取系统的网络配置信息,然后使用正则表达式解析输出以查找 mac 地址。它使用的系统命令是getmac(Windows) 或ifconfig(其他平台)。

