获取MAC地址

发布于 2024-10-03 23:27:41 字数 90 浏览 4 评论 0原文

我如何知道访问者在 Linux 托管 (nginx) 上的 MAC 地址?

来自以太网用户。

谢谢。

How do I know visitor's MAC address on linux hosting (nginx)?

From ethernet user.

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

无可置疑 2024-10-10 23:27:41

你无法通过 PHP 获得它。

网络协议在堆栈中使用。在进行 HTTP 通信时,您的 Web 服务器使用 HTTP 协议,负责高级通信。该协议是在 TCP 协议(​​带来类似流的连接和端口号)之上实现的,而 TCP 协议又是在 IP 协议(​​v4 或 v6,带来用于识别的 IP 地址)之上实现的,反过来是在以太网协议之上实现的。

以太网协议是您需要使用的协议。它同时具有源 MAC 地址和目标 MAC 地址。然而,最不幸的是,它存在很多问题。

首先,它传达的数据可能很难访问:我说“可能”是因为我从未偶然发现如何做到这一点。

其次,就像您在客户端访问您的站点时获取客户端的路由器地址一样,您也可以在以太网级别获取客户端的路由器 MAC 地址。除非它们不遍历任何路由器(只有当您的服务器直接连接到客户端计算机而没有任何路由器干扰时才会发生这种情况,因为那里有很多路由器将数据中继到互联网的其他部分),否则您收到的 MAC 地址不可能是您客户的。

第三,Apache 永远不会尝试访问该数据。由于 PHP 被“沙盒”到 Apache 提供的网络环境中,因此您无法回到以太网协议。

因此,从网站、PHP 访问访问者的 MAC 地址是不可能的。

编辑 看来您已经从问题中删除了 PHP 部分。显然,最后一点不再成立。

You cannot get that through PHP.

Networks protocol are used in a stack. When doing HTTP communications, your web server uses the HTTP protocol, responsible for the high-level communications. This protocol is implemented on the top of the TCP protocol (which brings stream-like connections and port numbers), which in turn is implemented on the top of the IP protocol (v4 or v6, which bring IP addresses for identification), which in turn is implemented on the top of the Ethernet protocol.

The Ethernet protocol is the one you would need to work with. It has both the source MAC address and the destination MAC address. However, most unfortunately, there are a lot of problems with it.

First, the data it conveys is probably hard to access: I say "probably" because I never stumbled upon how to do it.

Second, much like you get your client's router address when they access your site, you get your client's router MAC address at the Ethernet level. Unless they don't traverse any router (which would only happen if your server was directly wired to your client machine without any router interfering, because there are a whole lot of routers out there that relay data to other parts of the Internet), there is no chance that the MAC address you'll receive will be your client's.

Third, Apache will never try to access that data. And since PHP is "sandboxed" into the network environment Apache gives it, there is no way you can wind back to the Ethernet protocol.

So accessing the MAC address of a visitor from a website, from PHP, is not possible.

EDIT Seems you've taken out the PHP part from your question. So obviously, the last point won't stand anymore.

柒七 2024-10-10 23:27:41

你不能用 php 得到它,它不包含在 http 中

You can't get that with php it's not included in http

梦里°也失望 2024-10-10 23:27:41

更普遍的问题就是这个。由于所有 PHP 都必须处理 HTTP 请求(我假设这是在您的网络服务器上运行的 PHP),因此您将无法获取 MAC 地址。这需要在访问者这边运行一些东西。

The more general question is this one. Since all PHP has to work with (I'm assuming this is PHP running on your webserver, here) is the HTTP request, you won't be able to get the MAC address. That requires something running on the visitor's side.

偷得浮生 2024-10-10 23:27:41

这可能有效,也可能无效。我知道它适用于 LAN 客户端,但对于外部客户端来说可能不正确。我不太了解我的网络,但值得一试,对吗?

如果您在 Windows 或 Linux 上执行 arp -a 命令,它将打印出您的 arp 记录,然后您可以在 mac 上解析该记录。

除此之外,据我所知,apache(以及php)不仅仅在其环境变量中给出mac地址。

*编辑:抱歉,这行不通...更好的实用程序是 arping,但是它只会为您提供路由器的 mac。

如果你想这样做,客户端将需要直接连接到你的服务器,中间没有路由器...

但是如果是这样的话,那么 arping 将起作用...我不知道有更好的工具,但仅针对 mac 地址执行 ping(在 root 中)似乎有点浪费。

This may, or may not work. I know it will work on LAN clients, however for external clients it may be incorrect. I don't overly know my networking, but it's worth a shot right?

If you execute the arp -a command on either windows or linux, it will print out your arp records, which you can then parse for the mac.

Other than that, as far as I know, apache (and therefor php) doesn't just give out mac addresses in its env vars.

*Edited: Sorry, that won't work... The better utility is arping however that will just give you the mac of your router.

If you want to do this, clients will need to be directly connected to your server, with no router in between...

However if that is the case, then arping will work... I don't know of a better tool, but it seems a bit wasteful to do a ping (in root) for just a mac address.

梅窗月明清似水 2024-10-10 23:27:41

如果我是正确的,则 mac 地址仅对网络提供商可见(例如,您的互联网主机可以看到路由器的 mac 地址),不要认为您可以使用 php 获取它。

The mac address is only visible on for the network provider if i'm correct (your internet host can see the mac address of your router for example), don't think you can get it with php.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文