如何在linux上从c中的icmp回复中提取mac地址

发布于 2024-12-10 20:56:25 字数 141 浏览 3 评论 0原文

我试图在发送原始数据包后找出交换环境中机器的 MAC 地址。我正在尝试执行traceroute命令。我想知道当我收到 ICMP 超时消息时如何提取该机器的 MAC 地址。我是网络编程新手,所以很困惑什么套接字调用可以帮助我提取 mac 地址。

谢谢 。

I am trying to find out mac address of a machine in a switched environment after sending it a raw packet. I am trying to implement traceroute command . I want to know when i receive a ICMP time exceeded message how can I extract the mac address of that machine . I am a new to network programming so am confused what socket call will help me to extract the mac address.

Thanks .

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

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

发布评论

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

评论(3

孤城病女 2024-12-17 20:56:25

不,您无法从 ICMP 回复中提取 MAC 地址。

您只能确定您旁边的链接计算机的 MAC 地址。在ICMP(tracert)中,您只能找到目标或中间机器的IP地址。

如果你想检测 MAC 地址,你应该使用 ARP 协议,它适用于本地网络而不是互联网。

ICMP 协议在 IPv4 标头[1] 之后开始,MAC 地址与物理/链路层相关。在低层中,MAC 地址对于网络(IP)或传输等顶层是透明的。

要确定 MAC 地址,您应该使用原始套接字或 PCAP SDK 用于访问较低层的网络编程。 (我再说一遍,这些在互联网上没有用)

No, you can not extract MAC address from ICMP reply.

You can only determine MAC addresses of linked machines next to you. In ICMP(tracert) you can just find out the IP address of target or middle machine.

If you want to detect MAC addresses, you should use ARP protcols where it's applicable in local networks not Internet.

ICMP protocol starts after IPv4 header[1] and MAC addresses is related to physical/link layer. In low level layers the MAC addresses will transparent from top level layers such as network(IP) or Transmission,...

To determining MAC addresses, you should use Raw sockets or PCAP SDKs to access lower layers of network programming. (I say again, these are not useful over Internet)

帅冕 2024-12-17 20:56:25

正如 Masoud M 所说,您只能获取本地网络上计算机的 MAC 地址。也就是说,您可以解析 arp 命令的输出,根据本地网络中计算机的 IP 地址查找 MAC 地址。

Like Masoud M said, you can only get the MAC address of machines that are on your local network. That said, you can parse the output the arp command to find the MAC address given the IP address of a machine one your local network.

薄凉少年不暖心 2024-12-17 20:56:25

一般来说,在互联网上,您甚至不知道主机用于传输数据包的媒体。假设远程主机通过串行 rs-232-C 链路与 PPP 协议进行连接。它没有 MAC 地址。例如,如果主机使用令牌环接口或帧中继链路,也会发生这种情况。这使得确定主机的远程 MAC 地址完全成为本地问题。通常,当您通过以太网从远程站点获取数据包时,您在数据包中获得的源 MAC 地址是链接到互联网的最后一个路由器之一,而不是发送 IP 数据包的原始主机之一。在关于基于鸟类载体的 IP 的 RFC(rfc1149、rfc2549 和 rfc6214)中,用于传输的媒体不允许使用 mac 地址(链接地址,如果在 pidgeon 上可行的话,将是它的名称)

如果你想要要了解交换机以太网上的跟踪路由,也许您必须查看 IEEE802.1ag,它有一个在交换机上进行跟踪路由的规范(tracelink 服务)但我认为远远超出了这个答案的范围。

In general, on internet, you don't even know the media a host is using for transmitting packets. Let's suppose a remote host is conected over a serial rs-232-C link with PPP protocol. It doesn't have a mac address. This also happens for example if the host uses a token ring interface or frame relay link. This makes determining the remote mac addresses of hosts a local issue completely. Normally, when you get a packet from a remote site over ethernet, the source mac addres you get in the packet is the one of the last router that links you to the internet, not the one of the original host that sent the IP packet. In the RFC on IP over avian carriers (rfc1149, rfc2549 and rfc6214) the media used for transmission doesn't allow to use mac addresses (the link address, if somewhat feasible on a pidgeon could be, would be its name)

If you want to read about traceroute on ethernet network of switches, perhaps you had to have a look at the IEEE802.1ag, that has an specification to do tracerouting over switches (tracelink service) but I think is far over the scope of this answer.

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