如何将MAC地址转换为对应的IP地址? [英] How to convert a MAC address to the corresponding IP address?

查看:2247
本文介绍了如何将MAC地址转换为对应的IP地址?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要寻找一种简便的方式将MAC地址转换为相应的IP地址在本地网络。对我来说,只有两种设备:一个非常普通的PC(192.168.0.1),并具有任意的IP地址(192.168.0.xxx)硬盘$ C $在其ROM光盘科学仪器。 PC和仪器直接连接在使用CAT5电缆UDP套接字。

I am looking for an easy way to convert a MAC address to the corresponding IP address in a local network. In my case, there are only two devices: a very normal PC (192.168.0.1) and a scientific instrument which has an arbitrary IP address (192.168.0.xxx) hard coded in its ROM. The PC and the instrument are directly connected over a UDP socket with a CAT5 cable.

我知道仪器的MAC地址,但请假设它的IP地址是未知的。我想编写一个C / C ++应用程序,它使用套接字连接仪器会谈。但我需要(在Windows上的WinSock在OS X和Linux,SYS /插座)打开一个套接字之前就知道的IP地址。

I know the MAC address of the instrument, but please assume that its IP address is unknown. I would like to write a C/C++ application which talks with the instrument using a socket connection. But I need to know the IP address before opening a socket (WinSock on Windows, sys/socket on OS X and Linux).

目前我使用如下一个非常肮脏的方式。

Currently I use a very dirty way as shown below.


  1. 执行ping命令平192.168.0.2 (注意:仪器并不回应)

  2. 重复这个从192.168.0.2到192.168.0.255

  3. 执行 ARP -a 打印IP和MAC地址的列表

  4. 从列表中查找已知的MAC地址与对应的IP地址

  1. Execute ping command ping 192.168.0.2 (NOTE: the instrument does not respond to ping)
  2. Repeat this from 192.168.0.2 to 192.168.0.255
  3. Execute arp -a to print a list of IP and MAC addresses
  4. Find the known MAC address and the corresponding IP address from the list

我想知道如何在一个更复杂的方式取回的IP地址。这将是非常好的,如果我可以使用Mac,Linux和Windows机器的方法相同。

I would like to know how to retrieve the IP address in a more sophisticated way. It will be very nice if I can use the same method on Mac, Linux and Windows machines.

据我知道,我必须按顺序从已知IP地址的检索MAC地址广播ARP报文到网络。但我无法找到一个方法来从一个MAC地址的IP地址。

As far as I know, I have to broadcast a ARP packet to the network in order to retrieve a MAC address from a known IP address. But I could not find a way to get an IP address from a MAC address.

推荐答案

有是这个不行,通用的解决方案,因为它是预期的行为相反。下层协议不应该需要了解更高层的人,所以在MAC层操作没有发现关于IP地址的任何好办法。然后你进入你现在是这种情况。所以,你可以使用像code你已经有一个黑客,或者你可以从不同的方向解决这个。是否有任何非code的方式来确定前手设备的IP地址?如明确设置它或把它在一个配置文件,您的应用程序。或者,也可以让设备发送虚假的ARP请求?电脑应该根据关传入的请求,以及响应它发出的请求更新它的ARP缓存。

There's no good, generic solution for this as it is the reverse of intended behavior. Lower level protocols are not supposed to need to be aware of higher layer ones, so operations at the MAC layer don't have any good way of finding out about IP addresses. And then you get into the situation you're in now. So you can either employ a hack like the code you already have, or you can tackle this from a different direction. Is there any non-code way to determine the IP address of the device before hand? Such as setting it explicitly or putting it in a configuration file for your app. Alternatively, can you have the device send out spurious ARP requests? The PC should update its ARP cache based off of incoming requests as well as responses to requests it made.

这篇关于如何将MAC地址转换为对应的IP地址?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆