简体   繁体   English

nodejs获取客户端的mac地址

[英]nodejs get mac address of client

I created a Tcp server using net module in NodeJS and tried to get the mac address info from each client to generate uuid. 我使用NodeJS中的net模块创建了一个Tcp服务器,并尝试从每个客户端获取mac地址信息以生成uuid。 However, in the Socket object, there is no information about it. 但是,在Socket对象中,没有有关它的信息。 Also I tried to get read mac address from arp table, but it's not working either. 我也试图从arp表中读取mac地址,但是它也不起作用。 Any other ways to figure it out? 还有其他方法可以解决吗?

Because the MAC address belongs to the layer 2 of the OSI layers you will not be able to access it unless you are in the same address space because it gets stripped out by routers. 由于MAC地址属于OSI层的第2层,因此您将无法访问它,除非您位于同一地址空间中,因为它会被路由器剥离。

Explanation 说明

MAC address, belongs to layer 2 "Data Link Layer" of 7 OSI Layers . MAC地址,属于7个OSI层的第2层“数据链路层”。 The clients' MAC addresses are only visible to the routers they directly connect to. 客户端的MAC地址仅对它们直接连接的路由器可见。

Routers will partially disassemble the packet to get at the layer 3 "Network Layer" headers in order to determine where the packet should be shipped, where IP address is being used. 路由器将部分分解数据包,以到达第3层“网络层”标头,以确定数据包应运往何处,使用IP地址的位置。

Then, Layer 4, "Transport Layer", is where you're talking about specific protocols, like TCP. 然后,在第4层“传输层”中,您正在讨论诸如TCP之类的特定协议。

Therefore, as a server, you CANNOT get the clients' MAC address unless you are connected to your clients in layer 2. 因此,作为一个服务器,你不能 ,除非你是在第2层连接到您的客户得到客户的MAC地址。

I did something similar before for class rooms in production environment. 之前,我在生产环境中为教室做过类似的事情。 In my case, I have access to all client machines. 就我而言,我可以访问所有客户端计算机。 Either you have admin access to all clients or you can pre-register the client into your database somehow, you can do the following. 您具有对所有客户端的管理员访问权限,或者可以通过某种方式将客户端预注册到数据库中,可以执行以下操作。 If not, please ignore this answer. 如果没有,请忽略此答案。

  1. Create another NodeJs program hosted a web service in Clients (Don't forget to implement some kind of security). 创建另一个在客户端托管Web服务的NodeJs程序(不要忘记实现某种安全性)。 This program could be just a simple ExpressJs with getmac node module. 该程序可能只是带有getmac节点模块的简单ExpressJs。

  2. Register all IPs or domain name of the clients to Server database. 将客户端的所有IP或域名注册到服务器数据库。 Could be manual or, in my case, when Client turned-on it's auto send a request to server to register itself. 可能是手动的,或者就我而言,当客户端打开时,它会自动向服务器发送请求以进行自身注册。 (Implement client-server validation if needed) (如果需要,执行客户端-服务器验证)

  3. When Server needed the mac from client, Server app sends a request to each pre-registered client to get its mac address or any other information Server needs from clients. 当Server需要来自客户端的mac时,Server应用会向每个预先注册的客户端发送请求,以获取其mac地址或Server从客户端获取的任何其他信息。

Net client in node js does not provide the mac address. 节点js中的Net客户端不提供mac地址。 You have the choice between : 您可以选择:

1- sending the @mac your self: i mean in the client side you send the Mac address as data when you establish connection with the server. 1-发送自己的@mac:我的意思是在客户端与服务器建立连接时,将Mac地址作为数据发送。

2- use socket.io insteed net . 2-使用socket.io引导网。 It will afford you all the information you want 它将为您提供所需的所有信息

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM