SendARP返回错误的mac地址
C++ SendARP returns wrong mac address?
我试图检索设备的mac地址在我的局域网和我使用SendARP功能来做到这一点,但由于一些奇怪的原因,它给了我错误的mac地址,我告诉它得到我的笔记本电脑的mac也在局域网,但它不工作:/
链接到SendARP功能(MSDN): http://msdn.microsoft.com/en-us/library/windows/desktop/aa366358%28v=vs.85%29.aspx
笔记本电脑的MAC实际上是:e0:94:67:18:a7:dcSendARP: e9:ad:2d:01:c8:11
这是我创建的函数,用于简单地从ip地址获取mac: p
BYTE* GetMacAddress(IPAddr destination, IPAddr source) {
Sleep(500);
ULONG DestMacAddr[2];
ULONG PhysicalLength = 6;
memset(&DestMacAddr, 0xff, sizeof(DestMacAddr));
DWORD returnValue = SendARP(destination, source, &DestMacAddr, &PhysicalLength);
if(returnValue == NO_ERROR) {
cout << "Fetched destination mac" << endl;
}else {
printf("Error: %dn", returnValue);
if(returnValue == ERROR_BAD_NET_NAME) {
printf("ERROR_BAD_NET_NAMEn trying to fetch mac address...");
return GetMacAddress(destination, source);
}
if(returnValue == ERROR_BUFFER_OVERFLOW) {
printf("ERROR_BUFFER_OVERFLOWn");
}
if(returnValue == ERROR_GEN_FAILURE) {
printf("ERROR_GEN_FAILUREn");
}
if(returnValue == ERROR_INVALID_PARAMETER) {
printf("ERROR_INVALID_PARAMETERn");
}
if(returnValue == ERROR_INVALID_USER_BUFFER) {
printf("ERROR_INVALID_USER_BUFFERn");
}
if(returnValue == ERROR_NOT_FOUND) {
printf("ERROR_NOT_FOUNDn");
}
if(returnValue == ERROR_NOT_SUPPORTED) {
printf("ERROR_NOT_SUPPORTEDn");
}
}
BYTE *bMacAddr = (BYTE *) &DestMacAddr;
return bMacAddr;
}
我认为这可能是因为它是网络字节顺序或其他东西,但nothl()也没有工作:/请帮助我在这里:/
你不能这么做:
BYTE *bMacAddr = (BYTE *) &DestMacAddr;
return bMacAddr;
你正在返回一个指针,指向GetMacAddress()函数的堆栈上的某个东西,当函数结束时它将消失。
在命令提示符下输入'arp -a'查看本地arp表中笔记本电脑的MAC地址。如果它是不同的,那么原始然后键入'arp -d'(在Vista和Win7/8上具有管理员权限)清除arp表,并尝试使用yo SendARP应用程序再次检查mac。
相关文章:
- 动态获取 esp32 的 mac 地址并在以太网库中使用它.
- 将Wiimote MAC地址转换为PIN码,从C++转换为Python或Javascript
- 读取 MAC 地址时文件读取异常
- OMNET++:如何在INET 4.0中获取帧的源MAC地址?
- 获得MAC地址的代码似乎会损坏内存,但仅在发布构建中而不是调试构建
- 如何在 Windows 中使用 C++ 获取 MAC 地址
- MAC 地址解析
- Boost Regex用于格式化MAC地址字符串
- 从Netsh WLAN获取MAC地址
- Linux C++ 如何以编程方式获取 LAN 上所有适配器的 MAC 地址
- 将格式化的 mac 地址写入字符串流
- 如何在给定设备实例ID的情况下可靠快速地获取网卡的MAC地址
- 查找 DNS 服务器和网关的 IP 和 MAC 地址
- C 中的蓝牙 MAC 地址
- 在字符串向量中创建20000个MAC地址
- 获取系统的唯一标识符(而不是MAC地址)
- 如何使用本机 Wifi API C++获取 MAC 地址和信道信息
- C ++如何将我的命令行参数(MAC地址)转换为无符号字符
- 当您拥有蓝牙设备的名称时,您可以获取蓝牙设备的蓝牙MAC地址吗?
- 视觉 6.0 和查找 MAC 地址