获取另一台计算机的 MAC 地址(给定其 IP 地址)
可能的重复:
如何以编程方式在 MAC OS X 中查找 MAC 地址?< /a>
如何在 iPhone 上查询 ARP 表?
如果我知道另一台设备或计算机的 IP 地址,如何获取其 MAC 地址?
例如我有:
NSString * ip = @"192.168.1.1";
Possible Duplicates:
how to find MAC address in MAC OS X programmatically ?
How do I query the ARP table on iPhone?
How can I get the MAC address of another device or computer, if I know its IP address?
For example I have:
NSString * ip = @"192.168.1.1";
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您必须查找本地网络的 ARP(地址解析协议)表。在终端窗口中,您可以在命令行执行
arp -a
,它将打印出 ARP 表,其中显示本地网络 IP 地址及其物理地址关联(MAC 地址)。 OSX 将 ARP 条目存储在系统路由表中,但我找不到任何好的参考资料来说明如何将系统路由表中的条目转换为 MAC 地址:我打赌有一个 sysctl > 打电话到某个地方,但谁知道呢? 获取 MACOSX 上的路由表(以编程方式) 中有一个未解答的问题,该问题可能会导致帮助,但是...在 OSX 上,
arp
详细信息位于 http://developer.apple.com /library/mac/#documentation/Darwin/Reference/ManPages/man4/arp.4.html:我诚实地建议只进行系统
调用和过滤您所需的 IP 地址的结果。You have to look up the ARP (Address Resolution Protocol) table for the local network. From a Terminal window you can do
arp -a
at the command line and it will print out the ARP table which shows the local network IP addresses and their physical address associations (the MAC addresses). OSX stores the ARP entries in the system routing tables, but I can't find any good references that show how to translate the entries in the system routing table to MAC addresses: I'm betting there is asysctl
call somewhere, but who knows? There is one unanswered question at Getting routing table on MACOSX (programmatically) that may help, but...On OSX, the
arp
detail is at http://developer.apple.com/library/mac/#documentation/Darwin/Reference/ManPages/man4/arp.4.html: I'd honestly suggest just doing asystem
call and filtering the results for your desired IP address.