为什么服务器无法获取客户端 MAC 地址(例如客户端 IP)?
据我所知,数据包经过的所有MAC地址都在数据包中。这是因为在某个路径中进入的每个数据包也应该在类似的路径中返回。那么,如果服务器的路由器知道客户端(全部)的mac地址,为什么服务器页面(如aspx)不能拥有此信息?
请给个解释。 (不要只是告诉我我错了)。
如果我理解正确的话,客户端会发送一个包含其 MAC 地址的数据包。当数据包通过代理(如客户端路由器)时,代理的地址也会添加到数据包中。等等。
以下是维基百科上有关 TCP/IP 数据线层的片段:
http://en.wikipedia.org/wiki/TCP/IP_model#Data_Link_Layer
数据链路层用于移动 互联网层之间的数据包 两个不同主机的接口 相同的链接。的过程 发送和接收数据包 给定的链接可以在 软件设备驱动程序 网卡以及固件 或专用芯片组。这些将 执行数据链路功能,例如 添加数据包标头以准备它 对于传输,那么实际上 通过物理传输帧 中等的。 TCP/IP 模型包括 翻译规范 网络寻址方法中使用的 数据链路的互联网协议 寻址,例如媒体访问 控制 (MAC),但所有其他 低于该水平的方面是 隐含地假设存在于 链接层,但没有明确 已定义。
From what I know, all the MAC addresses that the packet gone through are in the packet. This is because that each packet that goes in a certain path, should also be returned in similar path. So, if the router of the server know about the mac address of the client (all of them), why the server page (like aspx) cannot have this information?
Please, give an explanation. (don't just tell me that I'm wrong).
If I understand it correctly, the client sends a packet that contains it's MAC address. when to packet go through a proxy (like the client router), the proxy's address is added to the packet too. and so on.
Here is a snippet from Wikipedia about the TCP/IP data line layer:
http://en.wikipedia.org/wiki/TCP/IP_model#Data_Link_Layer
The Data Link Layer is used to move
packets between the Internet Layer
interfaces of two different hosts on
the same link. The processes of
transmitting and receiving packets on
a given link can be controlled both in
the software device driver for the
network card, as well as on firmware
or specialized chipsets. These will
perform data link functions such as
adding a packet header to prepare it
for transmission, then actually
transmit the frame over a physical
medium. The TCP/IP model includes
specifications of translating the
network addressing methods used in the
Internet Protocol to data link
addressing, such as Media Access
Control (MAC), however all other
aspects below that level are
implicitly assumed to exist in the
Link Layer, but are not explicitly
defined.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(9)
实际上,存储在数据包中的 MAC 地址在数据包旅程的每一跳都会发生变化。
MAC 是媒体访问控制的简写,其中媒体指的是本地通信媒体。虽然源和目标 IP 地址在整个旅程中保持不变(并用于长距离路由决策),但源和目标 MAC 地址仅指示下一跳。
因此,服务器收到的数据包中存储的 MAC 地址应该是您的接入点路由器或提供商设备的 MAC 地址。
您可能想查看OSI层模型和封装。
Actually, the MAC-address stored in the packet is changed on every hop of a packet's journey.
MAC is shorthand for Media Access Control, with media refering to the local communication media. While source and destination IP-Addresses remain the same throughout the journey (and are used for long-distance routing decisions), the source and destination MAC-Addresses just indicate the next hop.
Because of this, the MAC-Address stored in packets received by your server should be the MAC address of your point of presence-router, or of the equipment of your provider.
You might want to have a look at the OSI Layer model and encapsulation.
IP 堆栈和物理堆栈之间的关系颠倒了。 MAC 地址位于包裹 IP 信息的部分,而不是相反。因此,当我从我的计算机向您的计算机发送某些内容时,我的 LAN(在本例中为以太网)中的物理网段会环绕 IP 内容并包括我的 MAC。然后,路由器提取 IP 信息,并在此过程中使用其自己的 MAC 将其向前向上(在本例中再次通过以太网)传递到我的 DSL 调制解调器。 DSL 调制解调器解开 IP 内容,并使用它使用的任何协议(当时不知道也不关心)将其发送到电话线......好吧,你明白了。每个物理链路跳点都使用底层物理层为本地传输附加的任何额外信息来包装和解开IP信息。
You have the relationship between the IP stack and the physical stack reversed. The MAC address is in the part that wraps the IP information, not the other way around. So when I send something from my computer, say, to yours, the physical segment in my LAN (Ethernet in this case) wraps around the IP stuff and includes my MAC. The router then extracts the IP information and passes that onward and upward (in this case again by Ethernet) to my DSL modem using its own MAC in the process. The DSL modem unwraps the IP stuff and sends that up the phone line using whatever protocol it uses (don't know and don't care at that point) out to ... well, you get the idea. Each physical link hop wraps and unwraps the IP information using whatever extra information the underlying physical layer involved attaches for local transmission.
在 IPv6 中,如果将 IPv6 地址编码为 64 位 主机地址。
另请参阅如何在使用 IPv6 时避免暴露我的 MAC 地址? 在超级用户上。
In IPv6, one might actually get the computer's MAC address from the IPv6 address, if encoded into the 64 bits of the host address.
See also How to avoid exposing my MAC address when using IPv6? on Super User.
不存在“服务器的路由器”。数据包可能从许多路由器到达服务器。
不存在“客户端的路由器”。数据包可能从客户端发送到许多路由器。
唯一可以看到 MAC 地址的设备是同一 LAN 上的设备 - 可能只有同一电缆段上的设备。
顺便说一句,如果客户端位于代理服务器的另一端,服务器也无法获取客户端 IP 地址。
There is no "router of the server". Packets may reach the server from many routers.
There is no "router of the client". Packets may be sent from the client to many routers.
The only devices which can see a MAC address are those on the same LAN - possibly only those on the same cable segment.
BTW, the server cannot get the client IP address, either, if the client is on the other side of a proxy server.
它的来源和保留的目标 IP 地址。网络间的思想基本上基于逐跳传送。中间路由器/主机仅了解 MAC 地址。据我所知,路由表应该理解机器地址。
MAC 地址是否可以在数据包的整个旅程中保留;这意味着不需要发明互联网协议地址。并且所有的互联网都将只使用 MAC 地址:-)
只有当服务器和服务器都可以实现你想要的东西时,你才能实现你想要的。客户端驻留在同一本地网络上(两台主机通过某些 L1 媒体连接)。
话虽如此,您的应用程序看起来有点像 Web 服务器,这告诉我它不需要位于同一网络上。
如果您想要接收主机上的源主机的 MAC 地址;考虑将其作为有效负载发送吗?
另外:
世界各地的网络不必是同一类型(即以太网、帧中继等)。网络层为我们提供了路由的灵活性,而不区分底层(数据链路层)或者我应该说底层L1技术。简而言之,IP 将为我们提供互联网络,而数据链路层(MAC 地址在此出现)将负责微观层面(即本地网络)的通信。这是 Mac 和 IP 地址共存的合理理由! :-)
It's source & destination IP address which remain. The idea of inter-network is basically based on hop-to-hop delivery. Intermediate routers/host understands only MAC addresses. To my knowledge routing tables should understand machine address.
If MAC addresses could remain throughout the journey of a packet; which means there was no need of Internet Protocol addresses to be invented. And all of the internet would have used only MAC addresses :-)
You can achieve what you want only if both the server & client reside on the same local network (both hosts are connected by some L1 media).
Having said that, your application looks something like a Web Server, which tells me that it need not be on the same network.
Still if you want the MAC address of the source host at the receiving host; think to sent it as a payload?
Addition:
Networks need not be of the same type around the world (viz. Ethernet, Frame relay etc). Network layer provides us with the flexibility of routing without distinction between underlying layers(Data Link Layer) or I should say underlying L1 technology. In short, IP will give us the inter-network and Data Link Layer(where MAC addresses come into picture) will take care of communication at micro level (i.e. local network). This is a fair reason why Mac and IP addresses co-exist! :-)
你不能 - 除非客户端位于你的服务器本地。如果是这样,您可以尝试对其进行 arp ping 并以这种方式获取客户端的 MAC 地址。
You can't - unless the client is local to your server. Provided it is, you can try arp-pinging it and getting the client's mac address that way.
您正在考虑服务器 LAN 和客户端 LAN 之间的直接连接,但这不是互联网的工作方式。两个 LAN 之间可以有任意数量的跃点,而且,任何一个 LAN 都没有使用 MAC 之类的东西的限制,因此“MAC 地址”不会放置在 IP 数据包中。 “MAC”仅在 LAN 内有意义(实际上,只有最低层确实使用 MAC 之类的东西;-),并且通过 ARP 和 RARP 协议发现/公布(这些协议不路由;-)。
You're thinking in terms of direct connection between the server's LAN and the client's LAN, and that's just not the way the internet works. There may be any number of hops between the two LANs -- and, by the way, there is no constraint that either LAN use anything like a MAC, so "MAC addresses" are not placed in IP packets. "A MAC" makes sense only within a LAN (actulaly, only one whose lowest layers do use something like MACs;-), and are discovered/announced with the ARP and RARP protocols (which do not get routed;-).
简单的区别是:IP 地址是端到端地址(当然在 IP 数据包中),而 MAC 地址仅逐跳使用。
此外,底层 MAC 协议可能会在客户端不知情的情况下在每一跳发生变化,因此客户端甚至可能无法理解其 IP 数据包沿途的所有地址。
The simple difference is: IP addresses are end to end adresses (in an IP packet of course), whereas MAC adresses are only used hop by hop.
Additionally the underlying MAC protocol could change on every hop, without knowledge of the client, therefore the client may not even understand all the adresses along the way of its IP packet.
在了解服务器为何无法访问客户端的 MAC 地址之前,我们先了解一下数据包如何在网络中传输。
情况 1:
网络应用程序知道目标 IP 地址,或者在应用程序仅知道域名的情况下从 DNS 服务器获取目标 IP 地址。
然后主机将目的IP地址与自己的IP地址和子网掩码进行比较。如果目标主机位于源主机的网络内,源主机将向网络发送 ARP 请求,询问“谁拥有该 IP 地址?”目的主机将回复其 MAC 地址。
情况 2:(通常是 Internet 上的情况)
如果目标主机不在源主机的网络内,假设我们在浏览 Google.com 时,DNS 会将名称解析为 IP 。源主机将发送一个 ARP 请求,询问“谁有我的默认网关的 IP 地址?”。在这种情况下,由于它不在我们的网络中,我们将向我们的默认网关发送 ARP 请求(默认网关是使用互联网协议套件的计算机网络中的节点,充当到其他网络的转发主机(路由器)), DG 回复其 MAC。您发送带有 Google 的目标 IP 和我们 DG 的目标 MAC 的数据包。当 DG 收到此帧时,其 IP 标头中带有自己的目标 MAC 和其他目标 IP 地址,它知道该数据包不是发往自己的,而只是穿越。然后继续进行 google 的 ip 查找,然后继续进行下一跳的 ARP 等。
所以你看,进行物理寻址的数据链路层永远不知道目的地的 MAC 地址,它只知道下一跳(路由器)的 MAC 地址。通过ARP请求获取下一个路由器的MAC地址。那么接收方如何知道发送方的MAC地址呢?它永远不知道,也不可能知道,因为每次路由器收到数据包时,它都会在源 MAC 地址字段中添加自己的 MAC 地址,或者更确切地说,它用自己的 MAC 地址替换它。因此,服务器将永远无法知道其接收者的 MAC 地址,因为它从未出现在数据包中。它只是保留的 IP 地址。
Before understanding that why the server cannot access the MAC address of its client, lets understand how a data packet traverse in a network.
Case 1 :
The destination IP address will be known to the network application or obtained from a DNS server in case the application knows a domain name only.
Then the host will compare the destination IP address with its own IP address and subnet mask. If the destination host is within the source host's network, the source host will send an ARP request onto the wire asking "who has that IP address?" and the destination host will reply with its MAC address.
Case 2 : (which is generally the case over the Internet)
If the destination host is not within the source host's network, lets say when we are browsing Google.com, the DNS will resolve the Name to IP. the source host will send an ARP request asking "who has the IP address of my default gateway?". In this case since it is out of our network, we will send ARP request to our Default Gateway(A default gateway is the node in a computer network using the internet protocol suite that serves as the forwarding host (router) to other networks), and DG replies with its MAC. You send the packet with Destination IP of Google and Destination MAC of our DG. When the DG recieves this Frame with its own destination MAC and some other destination IP address in the IP Header, it knows that the packet is not destined to itself, but only traversing. Then the ip lookup for google, followed by ARP for next hop etc continues..
So you see, the data link layer that does physical addressing never knew the MAC address of the destination, it only knew the MAC address of next HOP(router). The MAC address of the next router is obtained through ARP request. So how does the receiver know MAC address of its sender. Well it never knew nor it can because every time the packet was received by a router, it added its own MAC address in the source MAC address field or rather say it replaced it with its own. Hence the server will never be able to know MAC address of its receiver as it never was there in the packet. Its just the IP address that remains.